问题:如何使用Python 3安装pip?
我要安装pip。它应支持Python 3,但需要setuptools,该工具仅适用于Python 2。
如何使用Python 3安装pip?
I want to install pip. It should support Python 3, but it requires setuptools, which is available only for Python 2.
How can I install pip with Python 3?
回答 0
编辑:手动安装和使用setuptools
不再是标准过程。
如果您运行的是Python 2.7.9+或Python 3.4+
恭喜,您应该已经pip
安装了。如果您不这样做,请继续阅读。
如果您正在运行类似Unix的系统
pip
如果您的Python版本低于2.7.9或3.4,或者您的系统出于任何原因未包含该软件包,通常可以通过软件包管理器进行安装。
以下是一些更常见发行版的说明。
在适用于Python 2.x的Debian(Wheezy和更高版本)和Ubuntu(Trusty Tahr和更高版本)上安装
从终端运行以下命令:
sudo apt-get install python-pip
在适用于Python 3.x的Debian(Wheezy和更高版本)和Ubuntu(Trusty Tahr和更高版本)上安装
从终端运行以下命令:
sudo apt-get install python3-pip
注意: 在全新安装的Debian / Ubuntu中,只有在执行以下操作后才能找到该软件包:
sudo apt-get update
pip
在适用于Python 2.x的CentOS 7上安装
在CentOS 7上,您必须先安装设置工具,然后再使用它来安装pip
,因为它没有直接的软件包。
sudo yum install python-setuptools
sudo easy_install pip
pip
在适用于Python 3.x的CentOS 7上安装
假设您从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发行版未在软件包repos中包含它
使用下面详细介绍的手动方法进行安装。
手动方式
如果您想手动进行操作,现在推荐的方法是使用安装说明中的get-pip.py
脚本进行pip
安装。
安装点子
要安装pip,请安全下载 get-pip.py
然后运行以下命令(可能需要管理员访问权限):
python get-pip.py
如果setuptools
尚未安装,get-pip.py
将为您安装setuptools。
edit: Manual installation and use of setuptools
is not the standard process anymore.
If you’re running Python 2.7.9+ or Python 3.4+
Congrats, you should already have pip
installed. If you do not, read onward.
If you’re running a Unix-like System
You can usually install the package for pip
through your package manager if your version of Python is older than 2.7.9 or 3.4, or if your system did not include it for whatever reason.
Instructions for some of the more common distros follow.
Installing on Debian (Wheezy and newer) and Ubuntu (Trusty Tahr and newer) for Python 2.x
Run the following command from a terminal:
sudo apt-get install python-pip
Installing on Debian (Wheezy and newer) and Ubuntu (Trusty Tahr and newer) for Python 3.x
Run the following command from a terminal:
sudo apt-get install python3-pip
Note: On a fresh Debian/Ubuntu install, the package may not be found until you do:
sudo apt-get update
Installing pip
on CentOS 7 for Python 2.x
On CentOS 7, you have to install setup tools first, and then use that to install pip
, as there is no direct package for it.
sudo yum install python-setuptools
sudo easy_install pip
Installing pip
on CentOS 7 for Python 3.x
Assuming you installed Python 3.4 from EPEL, you can install Python 3’s setup tools and use it to install pip
.
# First command requires you to have enabled EPEL for CentOS7
sudo yum install python34-setuptools
sudo easy_install pip
If your Unix/Linux distro doesn’t have it in package repos
Install using the manual way detailed below.
The manual way
If you want to do it the manual way, the now-recommended method is to install using the get-pip.py
script from pip
‘s installation instructions.
Install pip
To install pip, securely download get-pip.py
Then run the following (which may require administrator access):
python get-pip.py
If setuptools
is not already installed, get-pip.py
will install setuptools for you.
回答 1
我可以通过运行Ubuntu在python 3上安装pip sudo apt-get install python3-pip
。
I was able to install pip for python 3 on Ubuntu just by running sudo apt-get install python3-pip
.
回答 2
Python 3.4+ and Python 2.7.9+
Good news! Python 3.4 (released March 2014) ships with Pip. This is the best feature of any Python release. It makes the community’s wealth of libraries accessible to everyone. Newbies are no longer excluded by the prohibitive difficulty of setup. In shipping with a package manager, Python joins Ruby, Nodejs, Haskell, Perl, Go–almost every other contemporary language with a majority open-source community. Thank you Python.
Of course, that doesn’t mean Python packaging is problem solved. The experience remains frustrating. I discuss this at Does Python have a package/module management system?
Alas for everyone using an earlier Python. Manual instructions follow.
Python ≤ 2.7.8 and Python ≤ 3.3
Follow my detailed instructions at https://stackoverflow.com/a/12476379/284795 . Essentially
Official instructions
Per https://pip.pypa.io/en/stable/installing.html
Download , being careful to save it as a .py
file rather than .txt
. Then, run it from the command prompt.
python get-pip.py
You possibly need an administrator command prompt to do this. Follow http://technet.microsoft.com/en-us/library/cc947813(v=ws.10).aspx
For me, this installed Pip at C:\Python27\Scripts\pip.exe
. Find pip.exe
on your computer, then add its folder (eg. C:\Python27\Scripts
) to your path (Start / Edit environment variables). Now you should be able to run pip
from the command line. Try installing a package:
pip install httpie
There you go (hopefully)!
回答 3
对于Ubuntu 12.04或更旧版本,
sudo apt-get install python3-pip
将无法正常工作。而是使用:
sudo apt-get install python3-setuptools ca-certificates
sudo easy_install3 pip
For Ubuntu 12.04 or older,
sudo apt-get install python3-pip
won’t work. Instead, use:
sudo apt-get install python3-setuptools ca-certificates
sudo easy_install3 pip
回答 4
如果您使用的是python 3.4+
只需输入:
python3 -m pip
if you’re using python 3.4+
just type:
python3 -m pip
回答 5
2015年1月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
Update 2015-01-20:
As per https://pip.pypa.io/en/latest/installing.html the current way is:
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
I think that should work for any version
Original Answer:
wget http://python-distribute.org/distribute_setup.py
python distribute_setup.py
easy_install pip
回答 6
系统中的单个Python
要在Python中安装软件包,请始终遵循以下步骤:
- 如果包装是用于
python 2.x
:sudo python -m pip install [package]
- 如果包装是用于
python 3.x
:sudo python3 -m pip install [package]
注意:这是假设未为设置别名 python
通过这种方法,将不会混淆哪个Python版本正在接收该软件包。
多个Python
假设你有python3 ↔ python3.6
和python3.7 ↔ python3.7
- 要安装python3.6:
sudo python3 -m pip install [package]
- 要安装python3.7:
sudo python3.7 -m pip install [package]
这基本上与前面显示的方法相同。
注1
如何找到您的python3
命令产生的python :
ganesh@Ganesh:~$ python3 # Type in terminal
Python 3.6.6 (default, Sep 12 2018, 18:26:19) # Your python3 version
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
注意第二行中的python 3.6.6。
笔记2
更改python3
或python
指向以下内容:https : //askubuntu.com/questions/320996/how-to-make-python-program-command-execute-python-3
Single Python in system
To install packages in Python always follow these steps:
- If the package is for
python 2.x
: sudo python -m pip install [package]
- If the package is for
python 3.x
: sudo python3 -m pip install [package]
Note: This is assuming no alias is set for python
Through this method, there will be no confusion regarding which python version is receiving the package.
Multiple Pythons
Say you have python3 ↔ python3.6
and python3.7 ↔ python3.7
- To install for python3.6:
sudo python3 -m pip install [package]
- To instal for python3.7:
sudo python3.7 -m pip install [package]
This is essentially the same method as shown previously.
Note 1
How to find which python, your python3
command spawns:
ganesh@Ganesh:~$ python3 # Type in terminal
Python 3.6.6 (default, Sep 12 2018, 18:26:19) # Your python3 version
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Notice python 3.6.6 in the second line.
Note 2
Change what python3
or python
points to: https://askubuntu.com/questions/320996/how-to-make-python-program-command-execute-python-3
回答 7
python3 -m ensurepip
我不确定何时确切引入此功能,但尚不存在时会为我安装pip3。
python3 -m ensurepip
I’m not sure when exactly this was introduced, but it’s installed pip3 for me when it didn’t already exist.
回答 8
旧版的Homebrew
如果您使用的是macOS,请使用homebrew
。
brew install python3 # this installs python only
brew postinstall python3 # this command installs pip
另请注意,如果安装成功完成,则应检查控制台。有时没有(例如由于所有权引起的错误),但是人们只是忽略了日志。
更新-1.5之后的自制软件版本
根据官方的Homebrew页面:
在2018年3月1日,python公式将升级到Python 3.x,并且将添加python @ 2公式以安装Python 2.7(尽管这仅是小桶,因此默认情况下,不将python和python2添加到PATH中,而无需手动冲泡链接–force)。我们将维护python2,python3和python @ 3别名。
因此,要安装Python 3,请运行以下命令:
brew install python3
然后,pip
会自动安装,您可以通过来安装任何软件包pip install <package>
。
Older version of Homebrew
If you are on macOS, use homebrew
.
brew install python3 # this installs python only
brew postinstall python3 # this command installs pip
Also note that you should check the console if the install finished successfully. Sometimes it doesn’t (e.g. an error due to ownership), but people simply overlook the log.
UPDATED – Homebrew version after 1.5
According to the official Homebrew page:
On 1st March 2018 the python formula will be upgraded to Python 3.x and a python@2 formula will be added for installing Python 2.7 (although this will be keg-only so neither python nor python2 will be added to the PATH by default without a manual brew link –force). We will maintain python2, python3 and python@3 aliases.
So to install Python 3, run the following command:
brew install python3
Then, the pip
is installed automatically, and you can install any package by pip install <package>
.
回答 9
如果您使用多个不同版本的python,请尝试使用virtualenv
http://www.virtualenv.org/en/latest/virtualenv.html#installation
具有pip
针对每个本地环境的优势。
然后通过以下方式在当前目录中安装本地环境:
virtualenv -p /usr/local/bin/python3.3 ENV --verbose
请注意,您指定了系统上已安装的python二进制文件的路径。
然后在该文件夹中有一个本地pythonenvironment。 ./ENV
现在应该有 ./ENV/pip-3.3
用于
./ENV/pip-3.3 freeze
列出本地安装的库。
用于./ENV/pip-3.3 install packagename
在本地环境中安装。
用于./ENV/python3.3 pythonfile.py
运行您的python脚本。
If you use several different versions of python try using virtualenv
http://www.virtualenv.org/en/latest/virtualenv.html#installation
With the advantage of pip
for each local environment.
Then install a local environment in the current directory by:
virtualenv -p /usr/local/bin/python3.3 ENV --verbose
Note that you specify the path to a python binary you have installed on your system.
Then there are now an local pythonenvironment in that folder. ./ENV
Now there should be ./ENV/pip-3.3
use
./ENV/pip-3.3 freeze
to list the local installed libraries.
use ./ENV/pip-3.3 install packagename
to install at the local environment.
use ./ENV/python3.3 pythonfile.py
to run your python script.
回答 10
这是我在ubuntu 12.04上解决此问题的方法:
sudo apt-get install build-essential libncursesw5-dev libssl-dev libgdbm-dev libc6-dev libsqlite3-dev tk-dev
然后从源代码安装python3:
wget https://www.python.org/ftp/python/3.4.0/Python-3.4.0.tar.xz
tar xvf Python-3.4.0.tar.xz
cd Python-3.4.0
./configure
make
make test
sudo make install
当您全部安装完后,pip3将自动安装。
Here is my way to solve this problem at ubuntu 12.04:
sudo apt-get install build-essential libncursesw5-dev libssl-dev libgdbm-dev libc6-dev libsqlite3-dev tk-dev
Then install the python3 from source code:
wget https://www.python.org/ftp/python/3.4.0/Python-3.4.0.tar.xz
tar xvf Python-3.4.0.tar.xz
cd Python-3.4.0
./configure
make
make test
sudo make install
When you finished installing all of them, pip3 will get installed automatically.
回答 11
这就是我在OS X Mavericks上所做的工作,以使其正常工作。
首先,冲泡安装了
安装python 3.4
brew install python3
然后,我得到了最新版本的distribution:
wget https://pypi.python.org/packages/source/d/distribute/distribute-0.7.3.zip#md5=c6c59594a7b180af57af8a0cc0cf5b4a
unzip distribute-0.7.3.zip
cd distribute-0.7.3
sudo setup.py install
sudo easy_install-3.4 pip
sudo pip3.4 install virtualenv
sudo pip3.4 install virtualenvwrapper
mkvirtualenv py3
python --version
Python 3.4.1
我希望这有帮助。
This is what I did on OS X Mavericks to get this to work.
Firstly, have brew installed
Install python 3.4
brew install python3
Then I get the latest version of distribute:
wget https://pypi.python.org/packages/source/d/distribute/distribute-0.7.3.zip#md5=c6c59594a7b180af57af8a0cc0cf5b4a
unzip distribute-0.7.3.zip
cd distribute-0.7.3
sudo setup.py install
sudo easy_install-3.4 pip
sudo pip3.4 install virtualenv
sudo pip3.4 install virtualenvwrapper
mkvirtualenv py3
python --version
Python 3.4.1
I hope this helps.
回答 12
What’s New In Python 3.4
…
pip should always be available
…
By default, the commands pipX and pipX.Y will be installed on all platforms (where X.Y stands for the version of the Python installation), along with the pip Python package and its dependencies.
https://docs.python.org/3/whatsnew/3.4.html#whatsnew-pep-453
so if you have python 3.4 installed, you can just: sudo pip3 install xxx
回答 13
For python3 try this:
wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python
The good thing is that It will also detect what version of python you have (even if it’s an environment of python in your custom location). After this you can proceed normally with (for example)
pip install numpy
source: https://pypi.python.org/pypi/setuptools/1.1.6#upgrading-from-setuptools-0-6
回答 14
假设您处于高度受限的计算机环境中(例如我本人),而没有root访问权限或无法安装软件包…
在发布本文之前,我从未设置过Python / virtualenv的新/独立/原始/非根实例。我已经做了很多谷歌搜索工作。
- 确定您使用的是python(python2)还是python3,并正确设置PATH。(我严格是python3用户。)如果您是python2用户
python3
,python
则下面的所有命令都可以代替。 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
- 假设您使用的是兼容Bourne的外壳,例如bash
- 出色的是,此
virtualenv
软件包包括的独立版本,pip
并且setuptools
会自动神奇地安装到每个新的virtualenv中。这解决了鸡肉和鸡蛋的问题。
- 您可能想为此最终命令创建一个别名(或更新〜/ .bashrc等),以在每次登录时激活python virtualenv。记住所有这些路径和命令可能很痛苦。
- 现在检查您的python版本:
which python3
应该给出:/path/to/new/virtualenv/bin/python3
pip
也可以通过以下命令在virtualenv中进行检查which pip
:应该给出:/path/to/new/virtualenv/bin/pip
然后…点,点,点!
给新手Pythoneers的最后提示:开始时您不需要虚拟环境,但是以后会很高兴的。帮助开源/共享软件包的“假设情况”安装/升级方案。
参考:https : //virtualenv.pypa.io/en/latest/installation.html
Assuming you are in a highly restricted computer env (such as myself) without root access or ability to install packages…
I had never setup a fresh/standalone/raw/non-root instance of Python+virtualenv before this post. I had do quite a bit of Googling to make this work.
- 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
Then… pip, pip, pip!
Final tip to newbie Pythoneers: You don’t think you need virtualenv when you start, but you will be happy to have it later. Helps with “what if” installation / upgrade scenarios for open source / shared packages.
Ref: https://virtualenv.pypa.io/en/latest/installation.html
回答 15
pip
在您安装Python时一起安装。您可以使用
sudo pip install (module)
或
python3 -m pip install (module)
。
pip
is installed together when you install Python. You can use
sudo pip install (module)
or
python3 -m pip install (module)
.
回答 16
要安装pip,请安全下载get-pip.py。
然后运行以下命令:
python get-pip.py
如果您使用的是由操作系统或其他程序包管理器管理的Python安装,请务必谨慎。get-pip.py与这些工具不协调,可能会使您的系统处于不一致状态。
参考:PIP安装
To install pip, securely download get-pip.py.
Then run the following:
python get-pip.py
Be cautious if you’re using a Python install that’s managed by your operating system or another package manager. get-pip.py does not coordinate with those tools, and may leave your system in an inconsistent state.
Refer: PIP Installation
回答 17
对于Windows 8.1 / 10 OS用户,只需打开 cmd(命令提示符)
写这个: C:\Users\%USERNAME%\AppData\Local\Programs\Python\Python36-32\Scripts
然后
只需这样写:pip3 install
{软件包名称}
提示:Python36-32
对于新的python 3.x版本,文件夹的位置可能会有所不同
And for Windows 8.1/10 OS Users just open cmd (command prompt)
write this : C:\Users\%USERNAME%\AppData\Local\Programs\Python\Python36-32\Scripts
then
just write this : pip3 install
{name of package}
Hint: the location of folder Python36-32
may get different for new python 3.x versions
回答 18
如果您的Linux发行版中已经安装了Python,则应该可以使用系统的软件包管理器来安装PIP。这是可取的,因为系统安装的Python版本无法与Windows和Mac上使用的get-pip.py脚本很好地配合使用。
高级打包工具(Python 2.x)
sudo apt-get install python-pip
进阶套件工具(Python 3.x)
sudo apt-get install python3-pip
pacman软件包管理器(Python 2.x)
sudo pacman -S python2-pip
pacman软件包管理器(Python 3.x)
sudo pacman -S python-pip
Yum软件包管理器(Python 2.x)
sudo yum upgrade python-setuptools
sudo yum install python-pip python-wheel
Yum软件包管理器(Python 3.x)
sudo yum install python3 python3-wheel
Dandified Yum(Python 2.x)
sudo dnf upgrade python-setuptools
sudo dnf install python-pip python-wheel
Dandified Yum(Python 3.x)
sudo dnf install python3 python3-wheel
Zypper软件包管理器(Python 2.x)
sudo zypper install python-pip python-setuptools python-wheel
Zypper软件包管理器(Python 3.x)
sudo zypper install python3-pip python3-setuptools python3-wheel
If your Linux distro came with Python already installed, you should be able to install PIP using your system’s package manager. This is preferable since system-installed versions of Python do not play nicely with the get-pip.py script used on Windows and Mac.
Advanced Package Tool (Python 2.x)
sudo apt-get install python-pip
Advanced Package Tool (Python 3.x)
sudo apt-get install python3-pip
pacman Package Manager (Python 2.x)
sudo pacman -S python2-pip
pacman Package Manager (Python 3.x)
sudo pacman -S python-pip
Yum Package Manager (Python 2.x)
sudo yum upgrade python-setuptools
sudo yum install python-pip python-wheel
Yum Package Manager (Python 3.x)
sudo yum install python3 python3-wheel
Dandified Yum (Python 2.x)
sudo dnf upgrade python-setuptools
sudo dnf install python-pip python-wheel
Dandified Yum (Python 3.x)
sudo dnf install python3 python3-wheel
Zypper Package Manager (Python 2.x)
sudo zypper install python-pip python-setuptools python-wheel
Zypper Package Manager (Python 3.x)
sudo zypper install python3-pip python3-setuptools python3-wheel
回答 19
请按照以下步骤使用pip安装python 3:
步骤1:从此处下载安装Python
步骤2:您需要下载 get-pip.py
步骤3:下载get-pip.py之后,打开命令提示符,然后转到保存get-pip.py文件的目录。
步骤4:输入命令 python get-pip.py
在cmd中。
步骤5:Pip安装成功,通过cmd中的type命令验证pip安装 pip --version
Please follow below steps to install python 3 with pip:
Step 1 : Install Python from download here
Step 2 : you’ll need to download get-pip.py
Step 3 : After download get-pip.py , open your commant prompt and go to directory where your get-pip.py file saved .
Step 4 : Enter command python get-pip.py
in cmd.
Step 5 : Pip installed successfully , Verify pip installation by type command in cmd pip --version
回答 20
这是我复制粘贴的单线。
curl https://bootstrap.pypa.io/get-pip.py | python3
从使用get-pip.py安装:
要安装pip,请get-pip.py
通过以下链接安全下载:
get-pip.py。或者,使用curl:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
然后在下载了get-pip.py的文件夹中运行以下命令:
python get-pip.py
警告:如果您使用的是由操作系统或其他程序包管理器管理的Python安装,请务必谨慎。get-pip.py与这些工具不协调,可能会使您的系统处于不一致状态。
This is the one-liner I copy-and-paste.
curl https://bootstrap.pypa.io/get-pip.py | python3
From Installing with get-pip.py:
To install pip, securely download get-pip.py
by following this link:
get-pip.py. Alternatively, use
curl:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Then run the following command in the folder where you have downloaded get-pip.py:
python get-pip.py
Warning: Be cautious if you are using a Python install that is managed by your operating system or another package manager. get-pip.py does not coordinate with those tools, and may leave your system in an inconsistent state.
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。