python之修改pip默认install路径

windows 环境下,Python pip 安装库的时候,默认安装在c盘,比如C:\Users\eric\AppData\Roaming\Python\Python37\site-packages
可以修改默认的安装路径,方便统一管理

  • 查看目前默认安装路径
F:\>python -m site
sys.path = [
    'F:\\',
    'D:\\Programs\\Python\\Python37\\python37.zip',
    'D:\\Programs\\Python\\Python37\\DLLs',
    'D:\\Programs\\Python\\Python37\\lib',
    'D:\\Programs\\Python\\Python37',
    'C:\\Users\\eric\\AppData\\Roaming\\Python\\Python37\\site-packages',
    'D:\\Programs\\Python\\Python37\\lib\\site-packages',
]
USER_BASE: 'C:\\Users\\eric\\AppData\\Roaming\\Python' (exists)
USER_SITE: 'C:\\Users\\eric\\AppData\\Roaming\\Python\\Python37\\site-packages' (exists)
ENABLE_USER_SITE: True

其中, USER_BASE和USER_SITE就是默认的路径

  • 查看配置文件
F:\>python -m site --help
D:\Programs\Python\Python37\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
 >2 - unknown error

D:\Programs\Python\Python37\lib\site.py,就是配置文件的路径

  • 修改D:\Programs\Python\Python37\lib\site.py
ENABLE_USER_SITE = True
USER_SITE = r"D:\Programs\Python\Python37\Lib\site-packages"	
USER_BASE = r"D:\Programs\Python\Python37\Scripts"	
  • 再次查看
F:\>python -m site
sys.path = [
    'F:\\',
    'D:\\Programs\\Python\\Python37\\python37.zip',
    'D:\\Programs\\Python\\Python37\\DLLs',
    'D:\\Programs\\Python\\Python37\\lib',
    'D:\\Programs\\Python\\Python37',
    'D:\\Programs\\Python\\Python37\\Lib\\site-packages',
]
USER_BASE: 'D:\\Programs\\Python\\Python37\\Scripts' (exists)
USER_SITE: 'D:\\Programs\\Python\\Python37\\Lib\\site-packages' (exists)
ENABLE_USER_SITE: True
  • 测试
F:\>pip install pyusb
Collecting pyusb
  Using cached pyusb-1.1.1-py3-none-any.whl (58 kB)
Installing collected packages: pyusb
Successfully installed pyusb-1.1.1

F:\>pip install pyusb
Requirement already satisfied: pyusb in d:\programs\python\python37\lib\site-packages (1.1.1)

F:\>

你可能感兴趣的:(笔记收藏,pip)