欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

更改conda环境下,pip包安装默认路径

程序员文章站 2024-01-05 09:47:04
...

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'
USER_BASE = '/home/users/xxx/anaconda3/envs/gluon-cv/lib/python3.6/site-packages'

修改后再次运行 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/lib/python3.6/site-packages' (exists)
USER_SITE: '/home/users/xxx/anaconda3/envs/gluon-cv' (exists)
ENABLE_USER_SITE: True

这个时候pip默认安装路径就修改成功了~

上一篇:

下一篇: