Linux下修改conda环境下的pip安装目录

一、问题

        我在linux服务器上新建一个conda环境后,在pip安装包的时候,老是出现我已在其他目录下安装的提示(如下所示)。我的pip安装路径应该是/home/Bxl/.conda/envs/hjw01/lib/python3.6/site-packages/,而不是/home/Bxl/.conda/envs/hjw/lib/python3.6/site-packages/。

(hjw01) [Bxl@inspur whl]$ pip install requests-2.21.0-py2.py3-none-any.whl
Processing ./requests-2.21.0-py2.py3-none-any.whl
Requirement already satisfied: urllib3<1.25,>=1.21.1 in /home/Bxl/.conda/envs/hjw/lib/python3.6/site-packages/urllib3-1.24.3-py3.6.egg (from requests==2.21.0)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /home/Bxl/.conda/envs/hjw/lib/python3.6/site-packages/chardet-3.0.4-py3.6.egg (from requests==2.21.0)
Requirement already satisfied: certifi>=2017.4.17 in /home/Bxl/.conda/envs/hjw/lib/python3.6/site-packages (from requests==2.21.0)
Collecting idna<2.9,>=2.5 (from requests==2.21.0)

二、解决方法

        我采取的解决思路就是看pip的安装目录是否已经设定,通过一番查找后,发现是安装路径出了问题。解决方法如下:

        在激活conda环境的前提下,然后修改 site.py 中的USER_BASE和USER_SITE变量,site.py路径:/home/Bxl/.conda/envs/hjw01/lib/python3.6/site.py,修改后内容如下:(之后重启conda环境)

        

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/Bxl/.conda/envs/hjw01/lib/python3.6/site-packages'
USER_BASE = '/home/Bxl/.conda/envs/hjw01'


def makepath(*paths):
    dir = os.path.join(*paths)
    try:
        dir = os.path.abspath(dir)
    except OSError:
        pass
    return dir, os.path.normcase(dir)


def abs_paths():
    """Set all module __file__ and __cached__ attributes to an absolute path"""
    for m in set(sys.modules.values()):
        if (getattr(getattr(m, '__loader__', None), '__module__', None) not in
                ('_frozen_importlib', '_frozen_importlib_external')):
            continue   # don't mess with a PEP 302-supplied __file__
        try:
            m.__file__ = os.path.abspath(m.__file__)
        except (AttributeError, OSError):
            pass
        try:
            m.__cached__ = os.path.abspath(m.__cached__)
        except (AttributeError, OSError):
            pass

 

  • 6
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值