python 安装包的默认路径与更改
- 安装包命令如下: pip install numpy;
2.如何查看安装包的位置
python -m site ;
3.显示出来的结果如下:
C:\Users\siyaopeng>python -m site
sys.path = [
‘C:\Users\siyaopeng’,
‘E:\Python\python38.zip’,
‘E:\Python\DLLs’,
‘E:\Python\lib’,
‘E:\Python’,
‘E:\Python\lib\site-packages’,
]
USER_BASE: ‘C:\Users\siyaopeng\AppData\Roaming\Python’ (doesn’t exist)
USER_SITE: ‘C:\Users\siyaopeng\AppData\Roaming\Python\Python38\site-packages’ (doesn’t exist)
ENABLE_USER_SITE: True
user_site其实就是个人的site-packages默认安装路径了
4.下面就是到对应的文件夹去修改配置
5.cmd命令行窗口下键入:
python -m site -help
6.可以看到结果:
C:\Users\siyaopeng>python -m site -help
E:\Python\lib\site.py [–user-base] [–user-site]
Without arguments print some useful information
With arguments print the value of USER_BASE and/or USER_SITE separated
by ‘;’.
Exit codes with --user-base or --user-site:
0 - user site directory is enabled
1 - user site directory is disabled by user
2 - uses site directory is disabled by super user
or for security reasons
7.可以看出是E:\Python\lib\site.py来管理这些配置
8.进入这个文件中,修改USER_BASE和USER_SITE
9.USER_BASE:执行下载的pip等脚本路径是由USER_BASE决定
USER_SITE:要安装下载的site-packages的路径
10.如何检查是否已修改成功:
命令行pip已安装的包,显示请求已满足
C:\Users\siyaopeng>pip install numpy
Requirement already satisfied: numpy in e:\python\lib\site-packages (1.19.4)
Python 修改pip缓存目录
一、前言
安装好python后尽量将修改一下pip的缓存目录,否则pip就会将安装包都缓存在 C:\Users\你的用户名\AppData\Local\pip\cache 下,大量占用C盘空间
二、修改方法
输入命令,将缓存目录移动到E盘 E:\Python\pipcache
pip config set global.cache-dir "E:\Python\pipcache"
pip.ini 配置文件会自动写入新的目录位置
如果不是新安装的python,那么需要剪切 C:\Users\你的用户名\AppData\Local\pip\cache 下的文件粘贴到 E:\Python\pipcache 下
pip install “git+https://github.com/philferriere/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI”