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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM