【问题标题】:Global pip referenced within a conda environment在 conda 环境中引用的全局 pip
【发布时间】:2018-07-25 17:58:52
【问题描述】:

总而言之,我创建并激活了一个仅安装了 pip 的 conda 环境。然后我列出了环境中的 pip 包,并安装了我所有的全局包。我检查 pip 指向的位置,它正确指向新创建的环境。那么为什么它会列出我的全局包呢?此外,我确认我可以加载这些包。任何帮助深表感谢!你可以看到我在这里运行的所有代码(在 zsh 提示中):

➜  ~ git:(master) ✗ conda create -n pip_test_env pip
Solving environment: done

## Package Plan ##

  environment location: /Users/ethankeller/miniconda3/envs/pip_test_env

  added / updated specs: 
    - pip


The following NEW packages will be INSTALLED:

    ca-certificates: 2018.4.16-0       conda-forge
    certifi:         2018.4.16-py36_0  conda-forge
    ncurses:         6.1-0             conda-forge
    openssl:         1.0.2o-0          conda-forge
    pip:             18.0-py36_0       conda-forge
    python:          3.6.5-1           conda-forge
    readline:        7.0-haf1bffa_1    conda-forge
    setuptools:      40.0.0-py36_0     conda-forge
    sqlite:          3.20.1-0          conda-forge
    tk:              8.6.8-0           conda-forge
    wheel:           0.31.1-py36_0     conda-forge
    xz:              5.2.3-0           conda-forge
    zlib:            1.2.11-h470a237_3 conda-forge

Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate pip_test_env
#
# To deactivate an active environment, use
#
#     $ conda deactivate

➜  ~ git:(master) ✗ conda activate pip_test_env
(pip_test_env) ➜  ~ git:(master) ✗ which pip
/Users/ethankeller/miniconda3/envs/pip_test_env/bin/pip
(pip_test_env) ➜  ~ git:(master) ✗ pip list
Package                  Version  
------------------------ ---------
aide-design              0.0.12   
alabaster                0.7.11   
atomicwrites             1.1.5    
attrs                    18.1.0   
Babel                    2.6.0    
certifi                  2018.4.16
chardet                  3.0.4    
codecov                  2.0.15   
coverage                 4.5.1    
cycler                   0.10.0   
docutils                 0.14     
idna                     2.7      
imagesize                1.0.0    
Jinja2                   2.10     
kiwisolver               1.0.1    
latexcodec               1.0.5    
MarkupSafe               1.0      
matplotlib               2.2.2    
more-itertools           4.2.0    
numpy                    1.14.5   
oset                     0.1.3    
packaging                17.1     
pandas                   0.23.3   
Pint                     0.8.1    
pip                      18.0     
pipenv                   2018.7.1 
pluggy                   0.6.0    
py                       1.5.4    
pybtex                   0.21     
pybtex-docutils          0.2.1    
Pygments                 2.2.0    
pyparsing                2.2.0    
pytest                   3.6.3    
pytest-cov               2.5.1    
python-dateutil          2.7.3    
pytz                     2018.5   
PyYAML                   3.13     
requests                 2.19.1   
ruamel.yaml              0.15.44  
scipy                    1.1.0    
setuptools               40.0.0   
six                      1.11.0   
snowballstemmer          1.2.1    
Sphinx                   1.7.6    
sphinx-rtd-theme         0.4.0    
sphinxcontrib-bibtex     0.4.0    
sphinxcontrib-disqus     1.1.0    
sphinxcontrib-websupport 1.1.0    
urllib3                  1.23     
virtualenv               16.0.0   
virtualenv-clone         0.3.0    
wheel                    0.31.1   
(pip_test_env) ➜  ~ git:(master) ✗ 
(pip_test_env) ➜  ~ git:(master) ✗ pip --version
pip 18.0 from /Users/ethankeller/.local/lib/python3.6/site-packages/pip (python 3.6)

如您所见,which pippip --version 显示两个不同的位置。为什么?如何使用正确的(环境)pip 包?

【问题讨论】:

    标签: pip conda


    【解决方案1】:

    您已经回答了自己的问题。

    仔细看:

    (pip_test_env) ➜  ~ git:(master) ✗ which pip
    /Users/ethankeller/miniconda3/envs/pip_test_env/bin/pip
    
    (pip_test_env) ➜  ~ git:(master) ✗ pip --version
    pip 18.0 from /Users/ethankeller/.local/lib/python3.6/site-packages/pip (python 3.6)
    

    它正在从您的 conda 环境中获取 pip 可执行文件,但 pip 本身正在从 ~/.local/lib/python3.6/site-packages/pip 获取它的内部结构

    这个问题有很多参考:

    在有官方解决方案之前,您可以执行以下任一操作:

    echo "include-system-site-packages=false" >> $CONDA_PREFIX/pyvenv.cfg
    

    或者:

    export PYTHONNOUSERSITE=1
    

    更多参考资料:

    【讨论】:

    • 非常感谢您的帮助!根据docs.python.org/3/library/… 和您发布的两个“更多参考”,include-system-site-packages 的默认配置为 false。那么添加该文件会如何改变呢?我还没有将它设置为真......无论如何我都这样做了,它仍然有奇怪的行为。现在,安装 pip 18 后,我无法运行“pip list”,因为它抱怨 pip._internal 丢失。当我恢复到 9.0.3 时,这是固定的,但其他行为仍然存在。有什么建议吗?
    • Pip 在发布 10 后进行了重大更改。您可以在 github.com/pypa/pip/issues/5599 阅读有关您的错误的信息
    • 如果我是你,我只会将 ~/.local/lib/python3.6/ 移动到备份目录并从头开始
    猜你喜欢
    • 2017-11-17
    • 1970-01-01
    • 2020-07-21
    • 2020-08-05
    • 1970-01-01
    • 1970-01-01
    • 2021-12-16
    • 1970-01-01
    • 2021-03-11
    相关资源
    最近更新 更多