Python 在centos7上安装pip(3)的推荐方式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50408941/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Recommended way to install pip(3) on centos7
提问by shrimpdrake
I am interrested in knowing the recommended way to install pip3 for python3.6 (as of today, may 2018) on current version of centos7 (7.5.1804) and the accepted answer of How to install pip in CentOS 7?seems to be outdated because:
我很想知道在当前版本的 centos7 (7.5.1804) 上为 python3.6(截至今天,2018 年 5 月)安装 pip3 的推荐方法以及如何在 CentOS 7 中安装 pip?似乎已经过时,因为:
yum search -v pip
outputs (among other things):
输出(除其他外):
python2-pip.noarch : A tool for installing and managing Python 2 packages
Repo : epel
python34-pip.noarch : A tool for installing and managing Python3 packages
Repo : epel
and python34-pip
seems to be a (newer?) simpler way than the accepted answer of How to install pip in CentOS 7?:
并且python34-pip
似乎是一种(更新?)比如何在 CentOS 7 中安装 pip的公认答案更简单的方法?:
sudo yum install python34-setuptools
sudo easy_install-3.4 pip
须藤 yum 安装 python34-setuptools
须藤easy_install-3.4 pip
But since the versions of python installed on my machine are 2.7.5 and 3.6.3 why is it python34-pip and not python36-pip ? Is pip the same for 3.4+ (up to current 3.6.3) ?
但是由于我机器上安装的 python 版本是 2.7.5 和 3.6.3 为什么是 python34-pip 而不是 python36-pip ?3.4+ 的 pip 是否相同(直到当前的 3.6.3)?
回答by hoefling
Is pip the same for 3.4+
No, it's not. A single
pip
installation serves a single Python distribution (pip2.7
/pip3.4
/pip3.5
etc).Since Python 3.5,
pip
is already bundled with the python distribution, so you can just runpython3.6 -m pip
instead ofpip
.Python 3.6 is not available in CentOS 7 vanilla repo. I usually resort to IUS repowhen needing to install a fresh Python on CentOS. It always has the most recent Python version, the current one being 3.6.5. It also offers a correspondent
pip
package.$ yum install https://centos7.iuscommunity.org/ius-release.rpm $ yum install python36u python36u-devel python36u-pip
Unfortunately, IUS doesn't offer a package for Python 3.7 yetso if you are looking for Python 3.7 on CentOS 7, building from source is your only option.
3.4+ 的 pip 是否相同
不,这不对。单个
pip
安装提供一个Python分布(pip2.7
/pip3.4
/pip3.5
等)。由于 Python 3.5
pip
已经与 Python 发行版捆绑在一起,因此您可以直接运行python3.6 -m pip
而不是pip
.Python 3.6 在 CentOS 7 vanilla 存储库中不可用。当需要在 CentOS 上安装新的 Python 时,我通常会求助于IUS 存储库。它始终具有最新的 Python 版本,当前版本是 3.6.5。它还提供了一个通讯
pip
包。$ yum install https://centos7.iuscommunity.org/ius-release.rpm $ yum install python36u python36u-devel python36u-pip
不幸的是,IUS还没有提供适用于 Python 3.7 的软件包,因此如果您正在 CentOS 7 上寻找 Python 3.7,那么从源代码构建是您唯一的选择。
Edit: when yum
is not an option
编辑:何时yum
不是一个选项
You should prefer the bootstrapping solution described in this answeras it is the most reliable way to get a working pip
installed.
您应该更喜欢本答案中描述的引导解决方案,因为它是pip
安装工作的最可靠方法。
回答by Андрей Наумов
To install pip for python 3.6 on CentOS 7 you need to run
要在 CentOS 7 上为 python 3.6 安装 pip,您需要运行
$ python3.6 -m ensurepip
$ python3.6 -m ensurepip
回答by Rajiv Sharma
Follow these commands in Centos 7
在 Centos 7 中遵循这些命令
yum install python36
yum install python36-devel
yum install python36-setuptools
easy_install-3.6 pip
to check the pip version:
检查 pip 版本:
pip3 -V
pip 18.0 from /usr/local/lib/python3.6/site-packages/pip-18.0-py3.6.egg/pip (python 3.6)
回答by Alan Ivey
There is now a python3-pip
package in the CentOS 7 base repositoryas of 2019-08-22. There is no longer a need for third-party repositories or packages.
截至 2019 年python3-pip
8 月 22 日,CentOS 7基础存储库中现在有一个软件包。不再需要第三方存储库或包。
Installing python3-pip
will also install libtirpc
, python3
, python3-libs
, and python3-setuptools
:
安装python3-pip
也将安装libtirpc
,python3
,python3-libs
,和python3-setuptools
:
yum install --assumeyes python3-pip
You can now verify the version (yes, it is old, but it's what is coming from the base repository):
您现在可以验证版本(是的,它是旧的,但它来自基础存储库):
$ pip3 --version
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)
If you don't want to stray from the files provided by the python3-pip
package, and you don't want to see warnings about pip being old, see https://stackoverflow.com/a/46288945/534275for silencing the messages.
如果您不想偏离python3-pip
包提供的文件,并且不想看到有关 pip 过时的警告,请参阅https://stackoverflow.com/a/46288945/534275以消除消息。
回答by Noam Manos
In case you're seeing that pip3 is linked to python2 path:
如果您看到 pip3 链接到 python2 路径:
$ pip3 -V
pip 8.1.2 from /usr/lib/python2.7/site-packages/pip (python 2.7)
$ pip3 -V
来自 /usr/lib/python2.7/site-packages/pip (python 2.7) 的 pip 8.1.2
You'll probably get:
你可能会得到:
$ pip3 install --upgrade pip
TypeError: parse() got an unexpected keyword argument 'transport_encoding'
$ pip3 install --upgrade pip
TypeError: parse() 得到了一个意外的关键字参数“transport_encoding”
Then try to clear commands cache with hash -r. This has worked for me:
然后尝试使用hash -r清除命令缓存。这对我有用:
# Install Python 3:
sudo yum install python36 -y
# Install & Upgrade pip3
sudo python36 -m pip install --upgrade pip
# Validate pip3 installation:
sudo python3.6 -m ensurepip
# Successfully installed pip-10.0.1 setuptools-39.0.1
# Clear commands cache
hash -r
# might be required if getting in bash: /usr/bin/pip3: No such file or directory)
pip3 -V
# pip 19.0.3 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
which pip3
# /usr/local/bin/pip3
pip2 -V
# pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7)
which pip2
# /usr/local/bin/pip2
# Install your Python3 module:
sudo /usr/local/bin/pip3 install {required module for python3}
回答by xjsc16x
Pip is not bundled in the EPEL version of python 3.6 for some reason. I assume a decent amount of people (such as me) will find this page because of that.
出于某种原因,Pip 没有捆绑在 python 3.6 的 EPEL 版本中。我假设相当数量的人(比如我)会因此找到这个页面。
$ sudo yum install -y python36
...
$ python36 -m pip
/usr/bin/python36: No module named pip
So in this case, the setuptools package was the easiest solution.
所以在这种情况下,setuptools 包是最简单的解决方案。
$ sudo yum install python36-setuptools
$ sudo easy_install-3.6 pip
...
$ python36 -m pip --version
pip 18.0 from /usr/local/lib/python3.6/site-packages/pip-18.0-py3.6.egg/pip (python 3.6)
回答by Sachin Verma
Try This::
尝试这个::
sudo yum update
sudo yum install -y python36u python36u-libs python36u-devel python36u-pip
Working for me perfectly.
完美地为我工作。
回答by eplt
I got this error when I tried to install python36 over the built-in centos7 python 2.7.5 version:
当我尝试通过内置的 centos7 python 2.7.5 版本安装 python36 时出现此错误:
Transaction check error:
file /etc/rpm/macros.python from install of python-rpm-macros-3-32.el7.noarch conflicts with file from package python-devel-2.7.5-80.el7_6.x86_64
And I fixed it with these:
我用这些修复了它:
yum install python36
yum update python-devel
yum install python36-devel
easy_install-3.6 pip