如何使用python命令运行不同版本python的pip?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34803040/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 15:32:31  来源:igfitidea点击:

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

pythonpython-3.xpippypipypy

提问by Alfred Huang

I'm now currently using Python on ubuntu 15.10

我现在在 ubuntu 15.10 上使用 Python

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

但是在我的操作系统中,我安装了许多不同的 python 版本:

  • Python (2.7.9)
  • Python3 (3.4.3)
  • Python3.5
  • PyPy
  • 蟒蛇(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.

事实上,我不能在里面导入 django python3.5

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

有什么有效的方法可以调用 的相关版本pip吗?

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

PS:不要建议我使用virtualenv,我知道并且正在寻求其他解决方案。

采纳答案by Alfred Huang

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

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.

这将分别适用于安装的每个版本的 python。

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

另外,根据文档,如果我们想在 Windows 中做同样的事情,命令有点不同:

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

回答by spacegoing

Why not using anaconda?

为什么不使用蟒蛇?

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

如果您使用conda,您可以轻松创建/管理虚拟环境。例如,如果你有rootenv python 3.4 和py27env for python 2.7,你可以很容易地在它们之间切换使用命令source activate [env]

source activate py27
conda install SomePackage

回答by masudak

How about using pyenv?

使用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

回答by Franke

This solution worked for me:

这个解决方案对我有用:

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