Wrong pip version for anaconda's environments. What should I do to correct the pip version when activate a env using `conda activate`?

好久不见. 提交于 2020-01-16 19:06:37

问题


I have 4 envs in my anaconda as listed below.

>>> conda info --envs
base                     /home/gph/anaconda3
py36_torch0.4         *  /home/gph/anaconda3/envs/py36_torch0.4
py37_torch1.1            /home/gph/anaconda3/envs/py37_torch1.1
python3.6                /home/gph/anaconda3/envs/python3.6

In both py36_torch0.4 and py37_torch1.1, I did some test.

>>>(py36_torch0.4) gph@gph-1050Ti:~ $ whereis pip
pip: /home/gph/.local/bin/pip3.5 
/home/gph/.local/bin/pip 
/home/gph/anaconda3/envs/py36_torch0.4/bin/pip3.6 
/home/gph/anaconda3/envs/py36_torch0.4/bin/pip

(py36_torch0.4) gph@gph-1050Ti:~ $ pip -V
pip 19.1.1 from /home/gph/.local/lib/python3.5/site-packages/pip (python 3.5)

(py37_torch1.1) gph@gph-1050Ti:~ $ whereis pip
pip: /home/gph/.local/bin/pip3.5 
/home/gph/.local/bin/pip 
/home/gph/anaconda3/envs/py37_torch1.1/bin/pip

(py37_torch1.1) gph@gph-1050Ti:~ $ pip -V
pip 19.1.1 from /home/gph/.local/lib/python3.5/site-packages/pip (python 3.5)

We can see that for each env_name we have envs/env_name/bin/pip, but the output of pip -V is always /home/gph/.local/lib/python3.5/site-packages/pip (python 3.5).
What is wrong? What should I do to make the pip version right when activate a specific env?

I have tried unset PYTHONPATH as told in this question: Wrong pip in conda env. But it is no use.


回答1:


You've installed pip outside of the conda environments, directly into your home directory. This takes precedence over everything that's installed in conda.

If you want to benefit from isolation of conda environments, you cannot install packages on the user level. This will get rid of all of them (but maybe also some more):

rm -rf /home/gph/.local

You might want to have a look at what else is installed in /home/gph/.local before actually removing it.




回答2:


Use pip as a module called by the Python interpreter of your env.

python -m pip install some_package where python is the one active on your env, for example /home/gph/anaconda3/envs/python3.6/bin/python.



来源:https://stackoverflow.com/questions/56593879/wrong-pip-version-for-anacondas-environments-what-should-i-do-to-correct-the-p

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!