ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

Python模块site及site.USER_BASE site.USER_SITE

2021-10-23 23:00:35  阅读:176  来源: 互联网

标签:users Python xxx site USER home packages


site
This module is automatically imported during initialization.

The automatic import can be suppresssed using the interpreter’s -S option.

-S: don't imply 'import site' on initialization

Disable the import of the module site and the site-dependent manipulations of sys.path that it entails.

Importing this module will append site-specific paths to the module search path and add a few builtins.

To explicitly trigger the usual site-specific additions, call the site.main() functions.

site.main()
Adds all the standard site-specific directories to the module search path.

This function is called automatically when this module is imported, unless the Python interpreter was started with the -S flag.

command line interface
python3 -m site --user-site # ~/.local/lib/python3.7/site-packages
1
–user-base : print the path to the user base directory

–user-site : print the path to the user site-packages directory

关键概念
USER BASE
site.USER_BASE , path to the base directory for the user site-packages

Default value is ~/.local for UNIX

USER SITE
site.USER_SITE, path to the user site-packages for the running Python.

Default value is ~/.local/lib/pythonX.Y/site-pacakges for UNIX
————————————————
版权声明:本文为CSDN博主「quantLearner」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/The_Time_Runner/article/details/106748763

======================================================================================================

更改conda环境下,pip包安装默认路径

tang-0203 2020-03-04 15:57:59 7886 收藏 14
分类专栏: Python学习 文章标签: python pip conda 默认安装路径
版权

Python学习
专栏收录该内容
26 篇文章0 订阅
订阅专栏
pip 指定某个路径安装包

# 在dir路径下,安装numpy包
pip install -t dir numpy
pip install --target dir numpy

设置pip默认安装路径
1、查看目前默认安装路径

在这里插入代码片
python -m site
# 显示内容
sys.path = [
'/home/users/xxx/anaconda3/envs/gluon-cv',
'/home/users/xxx/anaconda3/envs/gluon-cv/lib/python3.6/site-packages',
]
USER_BASE: '/home/users/xxx/.local' (exists)
USER_SITE: '/home/users/xxx/.local/lib/python3.6/site-packages' (exists)
ENABLE_USER_SITE: True

由于未知的原因,在gluon-cv这个环境下,默认安装路径指向了’/home/users/xxx/.local/lib/python3.6/site-packages’
2、重新设定USER_BASE和USER_SITE
首先conda激活环境,然后修改 site.py 中的USER_BASE和USER_SITE变量,site.py路径:~/anaconda3/envs/gluon-cv/lib/python3.6/site.py,修改后内容如下:

ImportError exception, it is silently ignored.
"""

import sys
import os
import builtins
import _sitebuiltins

# Prefixes for site-packages; add additional prefixes like /usr/local here
PREFIXES = [sys.prefix, sys.exec_prefix]
# Enable per user site-packages directory
# set it to False to disable the feature or True to force the feature
ENABLE_USER_SITE = None

# for distutils.commands.install
# These values are initialized by the getuserbase() and getusersitepackages()
# functions, through the main() function when Python starts.
USER_SITE = '/home/users/xxx/anaconda3/envs/gluon-cv/lib/python3.6/site-packages'
USER_BASE = '/home/users/xxx/anaconda3/envs/gluon-cv'

修改后再次运行 python -m site 查看,输出内容如下:

在这里插入代码片
sys.path = [
'/home/users/xxx/anaconda3/envs/gluon-cv',
'/home/users/xxx/anaconda3/envs/gluon-cv/lib/python3.6/site-packages',
]
USER_BASE: '/home/users/xxx/anaconda3/envs/gluon-cv' (exists)
USER_SITE: '/home/users/xxx/anaconda3/envs/gluon-cv/lib/python3.6/site-packages' (exists)
ENABLE_USER_SITE: True

这个时候pip默认安装路径就修改成功了~
————————————————
版权声明:本文为CSDN博主「tang-0203」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/tsq292978891/article/details/104655113

标签:users,Python,xxx,site,USER,home,packages
来源: https://www.cnblogs.com/akxmhd/p/15449871.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有