How to install pip in CentOS 7?
CentOS 7 EPEL now includes Python 3.4: yum install python34
However, when I try that, even though Python 3.4 installs successfully, it doesn't appear to install pip. Which is weird, because pip
should be included by default with Python 3.4. which pip3
doesn't find anything, nor does which pip
.
How do I access pip from the Python 3.4 package in CentOS 7 EPEL release?
The easiest way I've found to install pip3 (for python3.x packages) on CentOS 7 is:
$ sudo yum install python34-setuptools
$ sudo easy_install-3.4 pip
You'll need to have the EPEL repository enabled before hand, of course.
You should now be able to run commands like the following to install packages for python3.x:
$ pip3 install foo
curl https://bootstrap.pypa.io/get-pip.py | python3.4
Or if you don't have curl
for some reason:
wget https://bootstrap.pypa.io/get-pip.py
python3.4 get-pip.py
After this you should be able to run
$ pip3
The CentOS 7 yum package for python34 does include the ensurepip
module, but for some reason is missing the setuptools and pip files that should be a part of that module. To fix, download the latest wheels from PyPI into the module's _bundled
directory (/lib64/python3.4/ensurepip/_bundled/
):
setuptools-18.4-py2.py3-none-any.whl
pip-7.1.2-py2.py3-none-any.whl
then edit __init__.py
to match the downloaded versions:
_SETUPTOOLS_VERSION = "18.4"
_PIP_VERSION = "7.1.2"
after which python3.4 -m ensurepip
works as intended. Ensurepip is invoked automatically every time you create a virtual environment, for example:
pyvenv-3.4 py3
source py3/bin/activate
Hopefully RH will fix the broken Python3.4 yum package so that manual patching isn't needed.
Update: The python34 bug mentioned below has finally been fixed. It is a perfectly fine choice now.
Rather than using broken EPEL python34 packages, you can enable the IUS repo and have it work properly.
- pip inside virtual environments
The main python34u
and python35u
IUS packages include the pyvenv tool (/usr/bin/pyvenv-3.4
or /usr/bin/pyvenv-3.5
) that includes bundled wheels of pip and setuptools for bootstrapping virtual environments.
- global pip
The python34u-pip
and python35u-pip
IUS packages include /usr/bin/pip3.4
and /usr/bin/pip3.5
respectively. These work just fine to install packages to the system site-packages directory.
yum install python34-pip
pip3.4 install foo
You will likely need the EPEL repositories installed:
yum install -y epel-release