我想安装pip。它应该支持Python 3,但它需要setuptools,这只适用于Python 2。

如何在python3中安装pip ?


当前回答

如果你使用命令"python get-pip.py",你应该有Python3的'pip'函数。但是,Python2的'pip'可能仍然存在。在我的例子中,我卸载了'pip',这将它从Python2中删除。

之后,我再次运行“python get-pip.py”。(确保'get-pip.py'保存在与Python3相同的文件夹中。)最后一步是将带有'pip'命令的目录添加到$PATH。这为我解决了问题。

其他回答

对于Ubuntu 12.04或更高版本,

sudo apt-get install python3-pip

不能工作。相反,使用:

sudo apt-get install python3-setuptools ca-certificates
sudo easy_install3 pip
python3 -m ensurepip

我不确定这是什么时候引入的,但是当它还不存在的时候,我为它安装了pip3。

更新2015-01-20:

根据https://pip.pypa.io/en/latest/installing.html,目前的方式是:

wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py

我认为这适用于任何版本


最初的回答:

wget http://python-distribute.org/distribute_setup.py
python distribute_setup.py
easy_install pip

编辑:手动安装和使用setuptools不再是标准的过程。

如果你运行的是Python 2.7.9+或Python 3.4+

恭喜,您应该已经安装了pip。如果没有,继续读下去。

如果你运行的是类unix系统

如果您的Python版本高于2.7.9或3.4,或者您的系统由于某种原因没有包含pip,则通常可以通过包管理器安装pip包。

下面是一些比较常见的发行版的说明。

在Debian (Wheezy及更新版本)和Ubuntu (Trusty Tahr及更新版本)上安装Python 2.x

在终端上执行如下命令:

sudo apt-get install python-pip 

在Debian (Wheezy及更新版本)和Ubuntu (Trusty Tahr及更新版本)上安装Python 3.x

在终端上执行如下命令:

sudo apt-get install python3-pip

注意:

在一个新的Debian/Ubuntu安装中,这个包可能找不到,直到你这样做:

sudo apt-get update

在CentOS 7上为Python 2.x安装pip

在CentOS 7上,你必须先安装安装工具,然后使用它来安装pip,因为没有直接的软件包。

sudo yum install python-setuptools
sudo easy_install pip

在CentOS 7上为Python 3.x安装pip

假设您从EPEL安装了Python 3.4,您可以安装Python 3的设置工具并使用它来安装pip。

# First command requires you to have enabled EPEL for CentOS7
sudo yum install python34-setuptools
sudo easy_install pip

如果你的Unix/Linux发行版没有它的包回购

使用下面详细说明的手动方式安装。

手工方式

如果您想手动完成,现在推荐的方法是使用pip安装说明中的get-pip.py脚本进行安装。

pip安装 要安装pip,请安全地下载get-pip.py 然后运行以下命令(可能需要管理员访问): python get-pip.py 如果尚未安装setuptools, get-pip.py将为您安装setuptools。

假设你在一个高度受限的计算机环境中(比如我自己),没有root权限或安装包的能力……

在这篇文章之前,我从来没有设置过Python+virtualenv的新/独立/原始/非根实例。为了做到这一点,我在谷歌上搜索了很多。

Decide if you are using python (python2) or python3 and set your PATH correctly. (I am strictly a python3 user.) All commands below can substitute python3 for python if you are python2 user. wget https://pypi.python.org/packages/source/v/virtualenv/virtualenv-x.y.z.tar.gz tar -xzvf virtualenv-x.y.z.tar.gz python3 virtualenv-x.y.z/virtualenv.py --python $(which python3) /path/to/new/virtualenv source /path/to/new/virtualenv/bin/activate Assumes you are using a Bourne-compatible shell, e.g., bash Brilliantly, this virtualenv package includes a standalone version of pip and setuptools that are auto-magically installed into each new virtualenv. This solves the chicken and egg problem. You may want to create an alias (or update your ~/.bashrc, etc.) for this final command to activate the python virtualenv during each login. It can be a pain to remember all these paths and commands. Check your version of python now: which python3 should give: /path/to/new/virtualenv/bin/python3 Check pip is also available in the virtualenv via which pip... should give: /path/to/new/virtualenv/bin/pip

然后……皮皮,皮皮,皮皮!

给python新手的最后一个提示:在开始时,您认为不需要virtualenv,但以后会很高兴拥有它。帮助开源/共享包的“假设”安装/升级场景。

裁判:https://virtualenv.pypa.io/en/latest/installation.html