本文翻译自:How to install python3 version of package via pip on Ubuntu?
I have both python2.7
and python3.2
installed in Ubuntu 12.04
. 我在Ubuntu 12.04
安装了python2.7
和python3.2
。
The symbolic link python
links to python2.7
. 符号链接python
链接到python2.7
。
When I type: 当我输入:
sudo pip install package-name
It will default install python2
version of package-name
. 它将默认安装python2
版本的package-name
。
Some package supports both python2
and python3
. 一些包支持python2
和python3
。
How to install python3
version of package-name
via pip
? 如何通过pip
安装python3
版本的package-name
?
参考:https://stackoom.com/question/jA3s/如何在Ubuntu上通过pip安装python-版本的软件包
You may want to build a virtualenv
of python3, then install packages of python3 after activating the virtualenv. 您可能想要构建一个python3的virtualenv
,然后在激活virtualenv之后安装python3的包。 So your system won't be messed up :) 所以你的系统不会搞砸:)
This could be something like: 这可能是这样的:
virtualenv -p /usr/bin/python3 py3env
source py3env/bin/activate
pip install package-name
The easiest way to install latest pip2
/ pip3
and corresponding packages: 安装最新的pip2
/ pip3
和相应软件包的最简单方法:
curl https://bootstrap.pypa.io/get-pip.py | python2
pip2 install package-name
curl https://bootstrap.pypa.io/get-pip.py | python3
pip3 install package-name
Note: please run these commands as root
注意:请以root
身份运行这些命令
Firstly, you need to install pip for the Python 3 installation that you want. 首先,您需要为所需的Python 3安装安装pip。 Then you run that pip to install packages for that Python version. 然后运行该pip来安装该Python版本的包。
Since you have both pip and python 3 in /usr/bin, I assume they are both installed with a package manager of some sort. 既然你在/ usr / bin中都有pip和python 3,我认为它们都安装了某种包管理器。 That package manager should also have a Python 3 pip. 包管理器也应该有一个Python 3点。 That's the one you should install. 那是你应该安装的那个。
Felix' recommendation of virtualenv is a good one. 菲利克斯对virtualenv的推荐是一个很好的建议。 If you are only testing, or you are doing development, then you shouldn't install the package in the system python. 如果您只是在测试,或者您正在进行开发,那么您不应该在系统python中安装该软件包。 Using virtualenv, or even building your own Pythons for development, is better in those cases. 使用virtualenv,甚至构建自己的Pythons进行开发,在这些情况下更好。
But if you actually do want to install this package in the system python, installing pip for Python 3 is the way to go. 但是,如果你其实希望在系统蟒蛇安装该软件包,安装PIP为Python 3是要走的路。
If you have pip installed in both pythons, and both are in your path, just use: 如果您在两个pythons中安装了pip,并且两者都在您的路径中,请使用:
$ pip-2.7 install PACKAGENAME
$ pip-3.2 install PACKAGENAME
References: 参考文献:
This is a duplicate of question #2812520 这是问题#2812520的重复
Ubuntu 12.10+ and Fedora 13+ have a package called python3-pip
which will install pip-3.2
(or pip-3.3
, pip-3.4
or pip3
for newer versions) without needing this jumping through hoops. Ubuntu 12.10+和Fedora 13+有一个名为python3-pip
的软件包,它将安装pip-3.2
(或pip-3.3
, pip-3.4
或pip3
用于更新的版本),而不需要跳过这个环节。
I came across this and fixed this without needing the likes of wget
or virtualenvs (assuming Ubuntu 12.04): 我遇到了这个,并修复了这个,而不需要像wget
或virtualenvs(假设Ubuntu 12.04):
python3-setuptools
: run sudo aptitude install python3-setuptools
, this will give you the command easy_install3
. 安装包python3-setuptools
:运行sudo aptitude install python3-setuptools
,这将为您提供easy_install3
命令。 sudo easy_install3 pip
, this will give you the command pip-3.2
like kev's solution. 使用Python 3的setuptools安装pip:运行sudo easy_install3 pip
,这将为你提供命令pip-3.2
就像kev的解决方案一样。 sudo pip-3.2 install
(installing python packages into your base system requires root, of course). 安装你的PyPI包:运行sudo pip-3.2 install
(将python包安装到你的基本系统中当然需要root)。