简体   繁体   English

在centos7上安装pip(3)的推荐方式

[英]Recommended way to install pip(3) on centos7

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?我很想知道在当前版本的 centos7 (7.5.1804) 上为 python3.6(截至今天,2018 年 5 月)安装 pip3 的推荐方法以及如何在 CentOS 7 中安装 pip? seems to be outdated because:似乎已经过时,因为:

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似乎是一种(更新?) python34-pip CentOS 7 中安装 pip的公认答案更简单的方法 :

sudo yum install python34-setuptools须藤 yum 安装 python34-setuptools

sudo easy_install-3.4 pip须藤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 ?但是由于我机器上安装的 python 版本是 2.7.5 和 3.6.3 为什么是 python34-pip 而不是 python36-pip ? Is pip the same for 3.4+ (up to current 3.6.3) ? 3.4+ 的 pip 是否相同(直到当前的 3.6.3)?

  1. Is pip the same for 3.4+ 3.4+ 的 pip 是否相同

    No, it's not.不,这不对。 A single pip installation serves a single Python distribution ( pip2.7 / pip3.4 / pip3.5 etc).单个pip安装服务于单个 Python 发行版( pip2.7 / pip3.4 / pip3.5等)。

  2. Since Python 3.5, pip is already bundled with the python distribution, so you can just run python3.6 -m pip instead of pip .从 Python 3.5 开始, pip已经与 Python 发行版捆绑在一起,因此您只需运行python3.6 -m pip而不是pip

  3. Python 3.6 is not available in CentOS 7 vanilla repo. Python 3.6 在 CentOS 7 vanilla 存储库中不可用。 I usually resort to IUS repo when needing to install a fresh Python on CentOS.当需要在 CentOS 上安装新的 Python 时,我通常会求助于IUS 存储库 It always has the most recent Python version, the current one being 3.6.5 .它始终具有最新的 Python 版本, 当前版本是 3.6.5 It also offers a correspondent pip package .它还提供了相应的pip

     $ 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 yet so if you are looking for Python 3.7 on CentOS 7, building from source is your only option.不幸的是,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 answer as it is the most reliable way to get a working pip installed.您应该更喜欢本答案中描述的引导解决方案,因为它是安装工作pip的最可靠方法。

要在 CentOS 7 上为 python 3.6 安装 pip,您需要运行

$ python3.6 -m ensurepip

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)

There is now a python3-pip package in the CentOS 7 base repository as of 2019-08-22.截至 2019 年 8 月 22 日,CentOS 7基础存储库中现在有一个python3-pip包。 There is no longer a need for third-party repositories or packages.不再需要第三方存储库或包。

Installing python3-pip will also install libtirpc , python3 , python3-libs , and python3-setuptools :安装python3-pip还将安装libtirpcpython3python3-libspython3-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/534275 for silencing the messages.如果您不想偏离python3-pip包提供的文件,并且不想看到有关 pip 已旧的警告,请参阅https://stackoverflow.com/a/46288945/534275以消除消息。

Pip is not bundled in the EPEL version of python 3.6 for some reason.出于某种原因,Pip 没有捆绑在 python 3.6 的 EPEL 版本中。 I assume a decent amount of people (such as me) will find this page because of that.我假设相当数量的人(比如我)会因此找到这个页面。

$ 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)

In case you're seeing that pip3 is linked to python2 path:如果您看到 pip3 链接到 python2 路径:

$ pip3 -V $ pip3 -V

pip 8.1.2 from /usr/lib/python2.7/site-packages/pip (python 2.7)来自 /usr/lib/python2.7/site-packages/pip (python 2.7) 的 pip 8.1.2

You'll probably get:你可能会得到:

$ pip3 install --upgrade pip $ pip3 install --upgrade pip

TypeError: parse() got an unexpected keyword argument 'transport_encoding' TypeError: parse() 得到了一个意外的关键字参数“transport_encoding”

Then try to clear commands cache with hash -r .然后尝试使用hash -r清除命令缓存。 This has worked for me:这对我有用:

# 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}

Try This::尝试这个::

sudo yum update
sudo yum install -y python36u python36u-libs python36u-devel python36u-pip

Working for me perfectly.完美地为我工作。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM