在 conda 环境中引用的全局 pip

Eth*_*ler 3 pip conda

总而言之,我创建并激活了一个仅安装了 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)
Run Code Online (Sandbox Code Playgroud)

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

Neh*_*ani 5

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

仔细看:

(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)
Run Code Online (Sandbox Code Playgroud)

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

这个问题有很多参考:

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

echo "include-system-site-packages=false" >> $CONDA_PREFIX/pyvenv.cfg
Run Code Online (Sandbox Code Playgroud)

或者:

export PYTHONNOUSERSITE=1
Run Code Online (Sandbox Code Playgroud)

更多参考: