Python模块site及site.USER_BASE site.USER_SITE
2021/10/24 1:10:47
本文主要是介绍Python模块site及site.USER_BASE site.USER_SITE,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
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
这篇关于Python模块site及site.USER_BASE site.USER_SITE的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-30Python中''') 是什么?-icode9专业技术文章分享
- 2024-11-26Python基础编程
- 2024-11-25Python编程基础:变量与类型
- 2024-11-25Python编程基础与实践
- 2024-11-24Python编程基础详解
- 2024-11-21Python编程基础教程
- 2024-11-20Python编程基础与实践
- 2024-11-20Python编程基础与高级应用
- 2024-11-19Python 基础编程教程
- 2024-11-19Python基础入门教程