How to run pip of different version of python using python command?

﹥>﹥吖頭↗ 提交于 2019-11-26 03:57:14

问题


I\'m now currently using Python on ubuntu 15.10

But in my OS, I have many different python version installed:

  • Python (2.7.9)
  • Python3 (3.4.3)
  • Python3.5
  • PyPy

So, I got mess about the version of their package environment, for example, if I run:

pip3 install django

In fact I cannot import django inside python3.5.

Is there any efficiently way to call the relating version of pip?

PS: Don\'t suggest that I use virtualenv, I know about it and am seeking another solution.


回答1:


Finally I found the solution myself, see the Docs:

https://docs.python.org/3/installing/index.html?highlight=pip#work-with-multiple-versions-of-python-installed-in-parallel

Just call:

pythonXX -m pip install SomePackage

That would work separately for each version of installed python.

Also, according to the docs, if we want to do the same thing in windows, the command is a bit different:

py -2   -m pip install SomePackage  # default Python 2
py -2.7 -m pip install SomePackage  # specifically Python 2.7
py -3   -m pip install SomePackage  # default Python 3
py -3.4 -m pip install SomePackage  # specifically Python 3.4



回答2:


How about using pyenv?

You can switch the version.

$ pyenv install 2.7.X
$ pyenv install 3.5.X
$ pyenv local 2.7.X
$ pyenv global 3.5.X



回答3:


This solution worked for me:

sudo python2.7 -m pip install [package name]



回答4:


Why not using anaconda?

If you use conda, you can easily create/manage virtual env. For example, if you have root env python 3.4 and py27 env for python 2.7, you can easily switch between them use command source activate [env]

source activate py27
conda install SomePackage


来源:https://stackoverflow.com/questions/34803040/how-to-run-pip-of-different-version-of-python-using-python-command

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