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
======================================================================================================
更改conda環境下,pip包安裝預設路徑
tang-0203 2020-03-04 15:57:59 7886 收藏 14
分類專欄: Python學習 文章标簽: python pip conda 預設安裝路徑
版權
Python學習
專欄收錄該内容
訂閱專欄
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 檢視,輸出内容如下:
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)
這個時候pip預設安裝路徑就修改成功了~