Recommended way to install pip(3) on centos7

夙愿已清 提交于 2019-11-30 04:41:54
  1. 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).

  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.

  3. Python 3.6 is not available in CentOS 7 vanilla repo. I usually resort to IUS repo when 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 yet so if you are looking for Python 3.7 on CentOS 7, building from source is your only option.

Edit: when yum is not an option

You should prefer the bootstrapping solution described in this answer as it is the most reliable way to get a working pip installed.

To install pip for python 3.6 on CentOS 7 you need to run

$ python3.6 -m ensurepip

Follow these commands in Centos 7

yum install python36
yum install python36-devel
yum install python36-setuptools
easy_install-3.6 pip

to check the pip version:

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 python36-pip package in EPEL.

First, ensure EPEL is available and install epel-release if missing (this command works on a fresh system; ymmv depending on specific configurations of Yum repositories):

if ! { yum makecache fast >/dev/null 2>&1 && yum --cacheonly repolist enabled | grep -qE '^epel\/' ; }; then
  yum install --assumeyes epel-release
fi

Installing python36-pip will also install python36, python36-libs, and python36-setuptools:

yum install --assumeyes python36-pip

You can now verify the version (yes, it is old, but it's what is coming from EPEL):

$ pip3 --version
pip 8.1.2 from /usr/lib/python3.6/site-packages (python 3.6)

If you don't want to stray from the files provided by the python36-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.

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.

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

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

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

You'll probably get:

$ pip3 install --upgrade pip

TypeError: parse() got an unexpected keyword argument 'transport_encoding'

Then try to clear commands cache with 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!