[英]How to install pip with Python 3?
edit: Manual installation and use of setuptools
is not the standard process anymore.编辑:手动安装和使用setuptools
不再是标准过程。
Congrats, you should already have pip
installed.恭喜,您应该已经安装了pip
。 If you do not, read onward.如果您不这样做,请继续阅读。
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. 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.以下是一些更常见发行版的说明。
Run the following command from a terminal:从终端运行以下命令:
sudo apt-get install python-pip
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:在全新的 Debian/Ubuntu 安装中,可能无法找到 package,直到您执行以下操作:
sudo apt-get update
pip
on CentOS 7 for Python 2.x为 Python 2.x 在 CentOS 7 上安装pip
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.在 CentOS 7 上,您必须先安装设置工具,然后使用它来安装pip
,因为没有直接的 package 。
sudo yum install python-setuptools sudo easy_install pip
pip
on CentOS 7 for Python 3.x为 Python 3.x 在 CentOS 7 上安装pip
Assuming you installed Python 3.4 from EPEL , you can install Python 3's setup tools and use it to install 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
Install using the manual way detailed below.使用下面详述的手动方式安装。
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 .如果您想手动安装,现在推荐的方法是使用 pip pip
说明中的get-pip.py
脚本进行安装。
Install pip安装 pip
To install pip, securely download
get-pip.py
要安装 pip,请安全下载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.如果setuptools
尚未安装,get-pip.py
将为您安装 setuptools。
I was able to install pip for python 3 on Ubuntu just by running sudo apt-get install python3-pip
.只需运行sudo apt-get install python3-pip
,我就能够在 Ubuntu 上为 python 3 安装 pip 。
Good news!好消息! Python 3.4 (released March 2014) ships with Pip. Python 3.4 (2014 年 3 月发布)随 Pip 一起提供。 This is the best feature of any Python release.这是任何 Python 版本的最佳功能。 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. 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.谢谢 Python。
Of course, that doesn't mean Python packaging is problem solved.当然,这并不意味着 Python 封装问题就解决了。 The experience remains frustrating.经验仍然令人沮丧。 I discuss this at Does Python have a package/module management system?我在Python 有包/模块管理系统吗?
Alas for everyone using an earlier Python.对于使用早期 Python 的每个人来说都是遗憾的。 Manual instructions follow.手动说明如下。
Follow my detailed instructions at https://stackoverflow.com/a/12476379/284795 .按照我在https://stackoverflow.com/a/12476379/284795上的详细说明进行操作。 Essentially本质上
Per https://pip.pypa.io/en/stable/installing.html根据https://pip.pypa.io/en/stable/installing.html
Downloadget-pip.py
, being careful to save it as a .py
file rather than .txt
.下载get-pip.py
,注意将其保存为.py
文件而不是.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关注http://technet.microsoft.com/en-us/library/cc947813(v=ws.10).aspx
For me, this installed Pip at C:\Python27\Scripts\pip.exe
.对我来说,这在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).在您的计算机上找到pip.exe
,然后将其文件夹(例如C:\Python27\Scripts
)添加到您的路径(开始/编辑环境变量)。 Now you should be able to run pip
from the command line.现在您应该可以从命令行运行pip
了。 Try installing a package:尝试安装 package:
pip install httpie
There you go (hopefully)!你有 go(希望如此)!
if you're using python 3.4+如果您使用的是 python 3.4+
just type:只需输入:
python3 -m pip
For Ubuntu 12.04 or older,对于 Ubuntu 12.04 或更早版本,
sudo apt-get install python3-pip
won't work.不会工作。 Instead, use:相反,使用:
sudo apt-get install python3-setuptools ca-certificates
sudo easy_install3 pip
As per https://pip.pypa.io/en/latest/installing.html the current way is:根据https://pip.pypa.io/en/latest/installing.html目前的方式是:
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
I think that should work for any version我认为这应该适用于任何版本
wget http://python-distribute.org/distribute_setup.py
python distribute_setup.py
easy_install pip
Single Python in system系统中单 Python
To install packages in Python always follow these steps:要在 Python 中安装软件包,请始终按照以下步骤操作:
python 2.x
: sudo python -m pip install [package]
如果 package 用于python 2.x
: sudo python -m pip install [package]
python 3.x
: sudo python3 -m pip install [package]
如果 package 适用于python 3.x
: sudo python3 -m pip install [package]
Note: This is assuming no alias is set for python
注意:这是假设没有为python
设置别名
Through this method, there will be no confusion regarding which python version is receiving the package.通过这种方法,不会混淆哪个 python 版本正在接收 package。
Multiple Pythons多条蟒蛇
Say you have python3 ↔ python3.6
and python3.7 ↔ python3.7
假设你有python3 ↔ python3.6
和python3.7 ↔ python3.7
sudo python3 -m pip install [package]
要为python3.6安装: sudo python3 -m pip install [package]
sudo python3.7 -m pip install [package]
要为python3.7安装: sudo python3.7 -m pip install [package]
This is essentially the same method as shown previously.这与前面显示的方法基本相同。
Note 1注1
How to find which python?如何找到哪个 python? Do one of the following:执行以下操作之一:
~ » python3 -c "import sys; print(sys.version)"
3.9.5 (default, Nov 18 2021, 16:00:48)
your python3
command spawns:你的python3
命令产生:
~ » python3
Python 3.9.5 (default, Nov 18 2021, 16:00:48)
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Notice python 3.9.5 in the second line.注意第二行中的python 3.9.5 。
Note 2笔记2
Change what python3
or python
points to: https://askubuntu.com/questions/320996/how-to-make-python-program-command-execute-python-3更改python3
或python
指向的内容: https://askubuntu.com/questions/320996/how-to-make-python-program-command-execute-python-3
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.我不确定这是什么时候引入的,但是当它还不存在时,它已经为我安装了 pip3。
If you are on macOS, use homebrew
.如果您使用的是 macOS,请使用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 (eg an error due to ownership), but people simply overlook the log.有时它不会(例如由于所有权引起的错误),但人们只是忽略了日志。
According to the official Homebrew page :根据官方 Homebrew 页面:
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). 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手动冲泡链接--force)。 We will maintain python2, python3 and python@3 aliases.我们将维护 python2、python3 和 python@3 别名。
So to install Python 3, run the following command:所以要安装 Python 3,运行以下命令:
brew install python3
Then, the pip
is installed automatically, and you can install any package by pip install <package>
.然后,自动安装pip
,您可以通过pip install <package>
安装任何 package。
If your Linux distro came with Python already installed, you should be able to install PIP using your system's package manager. 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.这是更可取的,因为 Python 的系统安装版本不能很好地与 Windows 和 Mac 上使用的 get-pip.py 脚本配合使用。
Advanced Package Tool (Python 2.x)高级 Package 工具 (Python 2.x)
sudo apt-get install python-pip
Advanced Package Tool (Python 3.x)高级 Package 工具(Python 3.x)
sudo apt-get install python3-pip
pacman Package Manager (Python 2.x) pacman Package 管理器(Python 2.x)
sudo pacman -S python2-pip
pacman Package Manager (Python 3.x) pacman Package 管理器(Python 3.x)
sudo pacman -S python-pip
Yum Package Manager (Python 2.x)百胜 Package 经理(Python 2.x)
sudo yum upgrade python-setuptools
sudo yum install python-pip python-wheel
Yum Package Manager (Python 3.x)百胜 Package 经理(Python 3.x)
sudo yum install python3 python3-wheel
Dandified Yum (Python 2.x) Dandified Yum (Python 2.x)
sudo dnf upgrade python-setuptools
sudo dnf install python-pip python-wheel
Dandified Yum (Python 3.x) Dandified Yum (Python 3.x)
sudo dnf install python3 python3-wheel
Zypper Package Manager (Python 2.x) Zypper Package 管理器(Python 2.x)
sudo zypper install python-pip python-setuptools python-wheel
Zypper Package Manager (Python 3.x) Zypper Package 管理器(Python 3.x)
sudo zypper install python3-pip python3-setuptools python3-wheel
This is the one-liner I copy-and-paste:这是我复制和粘贴的单行:
curl https://bootstrap.pypa.io/get-pip.py | python3
Alternate:备用:
curl -L get-pip.io | python3
From Installing with get-pip.py :从使用 get-pip.py 安装:
To install pip, securely download
get-pip.py
by following this link: get-pip.py .要安装pip,请通过以下链接安全下载 get-pip.py:get-pip.pyget-pip.py
Alternatively, use curl:或者,使用 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:然后在下载 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.警告:如果您使用由您的操作系统或其他 package 管理器管理的 Python 安装,请务必小心。 get-pip.py does not coordinate with those tools, and may leave your system in an inconsistent state. get-pip.py 不与这些工具协调,并且可能会使您的系统处于不一致的 state 中。
If you use several different versions of python try using virtualenv
http://www.virtualenv.org/en/latest/virtualenv.html#installation如果您使用几个不同版本的 python 尝试使用virtualenv
http://www.virtualenv.org/en/latest/virtualenv.html#installation
With the advantage of pip
for each local environment.凭借pip
的优势,适用于每个本地环境。
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.请注意,您指定了系统上安装的 python 二进制文件的路径。
Then there are now an local pythonenvironment in that folder.然后该文件夹中现在有一个本地python环境。 ./ENV
Now there should be ./ENV/pip-3.3
现在应该有./ENV/pip-3.3
use ./ENV/pip-3.3 freeze
to list the local installed libraries.使用./ENV/pip-3.3 freeze
列出本地安装的库。
use ./ENV/pip-3.3 install packagename
to install at the local environment.使用./ENV/pip-3.3 install packagename
在本地环境安装。
use ./ENV/python3.3 pythonfile.py
to run your python script.使用./ENV/python3.3 pythonfile.py
运行您的 python 脚本。
Here is my way to solve this problem at ubuntu 12.04:这是我在 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:然后从源代码安装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
When you finished installing all of them, pip3 will get installed automatically.安装完所有这些后,pip3 将自动安装。
What's New In Python 3.4 Python 3.4 中的新增功能
... ...
pip should always be available pip 应始终可用
... ...
By default, the commands pipX and pipX.Y will be installed on all platforms (where XY stands for the version of the Python installation), along with the pip Python package and its dependencies. By default, the commands pipX and pipX.Y will be installed on all platforms (where XY 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-453https://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
所以如果你安装了 python 3.4,你可以: sudo pip3 install xxx
This is what I did on OS X Mavericks to get this to work.这就是我在 OS X Mavericks 上所做的以使其正常工作。
Firstly, have brew installed首先,安装brew
Install python 3.4安装 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.我希望这有帮助。
Please follow below steps to install python 3 with pip:请按照以下步骤安装 python 3 和 pip:
Step 1: Install Python from download here第 1 步:从此处下载安装 Python
Step 2: you'll need to download get-pip.py第 2 步:您需要下载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.第 3 步:下载 get-pip.py 后,打开命令提示符和 go 到保存 get-pip.py 文件的目录。
Step 4: Enter command python get-pip.py
in cmd.第 4 步:在 cmd 中输入命令python get-pip.py
get-pip.py。
Step 5: Pip installed successfully, Verify pip installation by type command in cmd pip --version
步骤5:Pip安装成功,通过cmd pip --version
中的type命令验证pip安装
For python3 try this:对于 python3 试试这个:
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).好消息是它还会检测您拥有的 python 版本(即使它是您自定义位置中的 python 环境)。 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来源: https://pypi.python.org/pypi/setuptools/1.1.6#upgrading-from-setuptools-0-6
Assuming you are in a highly restricted computer env (such as myself) without root access or ability to install packages...假设您处于高度受限的计算机环境(例如我自己)中,没有 root 访问权限或安装软件包的能力......
I had never setup a fresh/standalone/raw/non-root instance of Python+virtualenv before this post.在这篇文章之前,我从未设置过 Python+virtualenv 的全新/独立/原始/非根实例。 I had do quite a bit of Googling to make this work.我做了很多谷歌搜索来完成这项工作。
python3
for python
if you are python2 user. (我严格来说是 python3 用户。)如果您是 python2 用户,以下所有命令都可以用python3
替换python
。wget https://pypi.python.org/packages/source/v/virtualenv/virtualenv-xyztar.gz
tar -xzvf virtualenv-xyztar.gz
python3 virtualenv-xyz/virtualenv.py --python $(which python3) /path/to/new/virtualenv
source /path/to/new/virtualenv/bin/activate
virtualenv
package includes a standalone version of pip
and setuptools
that are auto-magically installed into each new virtualenv.出色的是,这个virtualenv
package 包括一个独立版本的pip
和自动安装到每个新 virtualenv 中的setuptools
。 This solves the chicken and egg problem.这解决了鸡和蛋的问题。which python3
should give: /path/to/new/virtualenv/bin/python3
现在检查您的 python 版本: which python3
应该给出的版本: /path/to/new/virtualenv/bin/python3
pip
is also available in the virtualenv via which pip
... should give: /path/to/new/virtualenv/bin/pip
检查pip
在 virtualenv 中也可用which pip
... 应该给出: /path/to/new/virtualenv/bin/pip
Then... pip, pip, 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.给新手 Pythoneers 的最后提示:刚开始时您并不认为需要 virtualenv,但以后会很高兴拥有它。 Helps with "what if" installation / upgrade scenarios for open source / shared packages.帮助解决开源/共享包的“假设”安装/升级方案。
Ref: https://virtualenv.pypa.io/en/latest/installation.html参考: https://virtualenv.pypa.io/en/latest/installation.html
To install pip, securely download get-pip.py .要安装 pip,请安全下载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.如果您使用的是由您的操作系统或其他 package 管理器管理的 Python 安装,请务必小心。 get-pip.py does not coordinate with those tools, and may leave your system in an inconsistent state. get-pip.py 不与这些工具协调,并且可能会使您的系统处于不一致的 state 中。
Refer: PIP Installation参考: PIP安装
pip
is installed together when you install Python. pip
是在安装 Python 时一起安装的。 You can use sudo pip install (module)
or python3 -m pip install (module)
.您可以使用sudo pip install (module)
或python3 -m pip install (module)
。
And for Windows 8.1/10 OS Users just open cmd (command prompt)对于Windows 8.1/10 OS 用户只需打开cmd(命令提示符)
write this: C:\Users\%USERNAME%\AppData\Local\Programs\Python\Python36-32\Scripts
写这个: C:\Users\%USERNAME%\AppData\Local\Programs\Python\Python36-32\Scripts
then然后
just write this: pip3 install
{name of package}只需这样写: pip3 install
{name of package}
Hint: the location of folder Python36-32
may get different for new python 3.x versions提示:对于新的 python 3.x 版本,文件夹Python36-32
的位置可能会有所不同
Below video is how I did in cygwin:下面的视频是我在 cygwin 中的表现:
https://asciinema.org/a/hSu4kmJ6wb7b2UiuvxiXqtgGK https://asciinema.org/a/hSu4kmJ6wb7b2UiuvxiXqtgGK
There is weirdness in python's pip
, pip2
, pip3
craziness. python 的pip
、 pip2
、 pip3
的疯狂有些奇怪。 In crazy situations like these, it is imperative that there is less talking or explanations, but instead demonstrate things out.在这种疯狂的情况下,必须减少谈话或解释,而是将事情展示出来。
=>Easy way to install Python any version on Ubuntu 18.04 or Ubuntu 20.04 follow these steps:- =>在 Ubuntu 18.04 或 Ubuntu 20.04 上安装 Python 任何版本的简便方法:--按照这些步骤:--
Step 1: Update Local Repositories:-第 1 步:更新本地存储库:-
sudo apt update
Step 2: Install Supporting Software:-第 2 步:安装支持软件:-
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
Step3: Create directory on your home directory To download the newest release of Python Source Code, navigate to the /python-source-files directory and use the wget command:-第 3 步:在您的主目录上创建目录 要下载最新版本的 Python 源代码,请导航到 /python-source-files 目录并使用 wget 命令:-
mkdir python-source-files
Step 4: Download the Latest Version of Python Source Code:-第四步:下载最新版Python源码:-
wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz
"you can change python version by just modifies this:-"3.7.5" with the version you want example:-"3.5.2" “您可以更改 python 版本,只需修改此:-“3.7.5”为您想要的版本例如:-“3.5.2”
Step 5: Extract Compressed Files:-第 5 步:提取压缩文件:-
tar –xf Python-3.7.5.tgz
or tar xvzf Python-3.7.5.tgz
tar –xf Python-3.7.5.tgz
或tar xvzf Python-3.7.5.tgz
Step 6: Test System and Optimize Python:-第 6 步:测试系统并优化 Python:-
cd python-3.7.5
or your version of python. cd python-3.7.5
或您的 python 版本。
Step 7: Now configure(Using the ––optimization option speeds code execution by 10-20%.):-第 7 步:现在配置(使用 ––optimization 选项可将代码执行速度提高 10-20%。):-
./configure ––enable–optimizations
OR you can also do this also if you facing ssl error:-或者,如果您遇到 ssl 错误,您也可以这样做:-
./configure --with-openssl
Step 8: Install a Second Instance of Python:-第 8 步:安装 Python 的第二个实例:-
sudo make altinstall
"It is recommended that you use the altinstall method. Your Ubuntu system may have software packages dependent on Python 2.x. “建议您使用altinstall方法。您的Ubuntu系统可能有依赖于Python 2.x的软件包。
OR或者
If you want to Overwrite Default Python Installation/version:-如果要覆盖默认 Python 安装/版本:-
sudo make install"
Step 9:Now check Python Version:-第 9 步:现在检查 Python 版本:-
python3 ––version
Step 10: To install pip for python3 just go with this command:-第 10 步:使用以下命令为 python3 安装 pip 只需 go:-
sudo apt-get install python3-pip
If you used the command "python get-pip.py", you should have the 'pip' function for Python3.如果你使用命令“python get-pip.py”,你应该有 Python3 的“pip”function。 However, 'pip' for Python2 might still be present.但是,Python2 的“pip”可能仍然存在。 In my case I uninstalled 'pip', which removed it from Python2.就我而言,我卸载了“pip”,它从 Python2 中删除了它。
After that I ran "python get-pip.py" again.之后我再次运行“python get-pip.py”。 (Make sure that 'get-pip.py' is saved in the same folder as Python3.) The final step was to add the directory with 'pip' command to $PATH. (确保“get-pip.py”保存在与 Python3 相同的文件夹中。)最后一步是将带有“pip”命令的目录添加到 $PATH。 That solved it for me.这为我解决了它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.