我在Ubuntu 12.04中同时安装了python2.7和python3.2。 符号链接python链接到python2.7。

当我输入:

sudo pip install package-name

它将默认安装python2版本的package-name。

有些包同时支持python2和python3。 如何通过pip安装python3版本的package-name ?


当前回答

如果你在两个python中都安装了pip,并且都在你的路径中,只需使用:

$ pip-2.7 install PACKAGENAME
$ pip-3.2 install PACKAGENAME

引用:

http://www.pip-installer.org/docs/pip/en/0.8.3/news.html#id4 https://github.com/pypa/pip/issues/200

这是问题2812520的副本

其他回答

如果你在两个python中都安装了pip,并且都在你的路径中,只需使用:

$ pip-2.7 install PACKAGENAME
$ pip-3.2 install PACKAGENAME

引用:

http://www.pip-installer.org/docs/pip/en/0.8.3/news.html#id4 https://github.com/pypa/pip/issues/200

这是问题2812520的副本

老问题了,但没有一个答案能让我满意。我的一个系统运行的是Ubuntu 12.04 LTS,由于某种原因,Python 3没有python3-pip或Python -pip包。下面是我所做的(所有命令都以root身份执行):

Install setuptools for Python3 in case you haven't. apt-get install python3-setuptools or aptitude install python3-setuptools With Python 2.4+ you can invoke easy_install with specific Python version by using python -m easy_install. So pip for Python 3 could be installed by: python3 -m easy_install pip That's it, you got pip for Python 3. Now just invoke pip with the specific version of Python to install package for Python 3. For example, with Python 3.2 installed on my system, I used: pip-3.2 install [package]

您可能想要构建一个python3的virtualenv,然后在激活virtualenv后安装python3的包。这样你的系统就不会乱套了:)

这可能是这样的:

virtualenv -p /usr/bin/python3 py3env
source py3env/bin/activate
pip install package-name

安装python3的另一种方法是使用wget。下面是安装步骤。

wget http://www.python.org/ftp/python/3.3.5/Python-3.3.5.tar.xz
tar xJf ./Python-3.3.5.tar.xz
cd ./Python-3.3.5
./configure --prefix=/opt/python3.3
make && sudo make install

此外,还可以为相同的用途创建别名

echo 'alias py="/opt/python3.3/bin/python3.3"' >> ~/.bashrc

现在打开一个新终端,输入py并按Enter。

如果您的系统默认使用python2,使用下面的命令将包安装到python3

$ python3 -m PIP install <package-name>