Reputation: 1053
To summarize, I create and activate a conda environment with just pip installed. Then I list the pip packages within the environment and all my global packages are installed. I check where pip is pointing, and it is correctly pointing to the newly created environment. So why does it list my global packages? Furthermore, I confirmed that I can load the packages. Any help is much appreciated! You can see all the code I ran here (within zsh prompts):
➜ ~ 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)
As you can see, which pip
and pip --version
show two different locations. Why? How do I use the correct (the environment) pip package?
Upvotes: 4
Views: 2254
Reputation: 16639
You have answered your own question.
Look carefully at:
(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)
It is picking up the pip executable from your conda environment, but pip itself is picking up it's internals from ~/.local/lib/python3.6/site-packages/pip
There are many references to this issue:
Till there is an official solution out, you can do either of the following:
echo "include-system-site-packages=false" >> $CONDA_PREFIX/pyvenv.cfg
OR:
export PYTHONNOUSERSITE=1
More references:
Upvotes: 7