112

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?

Jeff Widman
  • 22,014
  • 12
  • 72
  • 88
  • 3
    probably related: http://stackoverflow.com/questions/26576086/no-pip-binary-after-installing-python-3-4-2-on-centos-6-5 – cel Sep 16 '15 at 21:06
  • 1
    I looked through there, but nothing relates unfortunately. – Jeff Widman Sep 16 '15 at 21:18
  • So there's no `pip34` binary? Well, you will always be able to call pip via `python -m pip` if it is installed. If it is not installed `python -m ensurepip` can be used to bootstrap it. You may need elevated rights to call the latter command. – cel Sep 16 '15 at 21:25
  • 1
    Correct, no `pip*` binary that I can find in `/usr/bin/`. Fairly sure I'm looking in the right place because that's where `python3.4` and `pyvenv-3.4` where installed, and they aren't symlinked to somewhere else. Ah well, looks like it's simply not included in the python3.4 package which is a bit annoying. The `ensurepip` module doesn't exist for `python3.4` either, so I'll probably just use the iUS repos until EPEL ships `python3-pip` or equivalent. – Jeff Widman Sep 16 '15 at 21:29
  • Weird, IIRC every `python3.4` installation should have the `ensurepip` module. In that case there's also a `get-pip.py` script, that can bootstrap pip for you. – cel Sep 16 '15 at 21:36
  • 1
    Apparently, the python3 [EPEL effort](https://fedoraproject.org/wiki/User:Bkabrda/EPEL7_Python3) is still in an [early stage](https://bugzilla.redhat.com/show_bug.cgi?id=1219411). See also [pyvenv3.4 doesn't work without pip](https://bugzilla.redhat.com/show_bug.cgi?id=1263057) and [python34's ensurepip is broken](https://bugzilla.redhat.com/show_bug.cgi?id=1319963). – maxschlepzig Oct 08 '16 at 18:09

10 Answers10

158

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
foobrew
  • 1,766
  • 1
  • 11
  • 3
  • I think this is the best solution too, while keeping everything sane. I dont recommend editing __init__.py – laapsaap Oct 29 '16 at 16:51
  • Agreed best solution make this the default answer – johhny B Dec 15 '16 at 21:32
  • 7
    On my RHEL-7 system, with EPEL set up, I just successfully did `yum install python34-pip` – some bits flipped Jul 28 '17 at 22:53
  • 2
    Worth noting that `easy_install-3.4 pip` overwrote the system `pip`. I did a `yum reinstall python-pip` afterwards to ensure no problems. This means that you must explicitly call `pip3` to use it, as expected. – miken32 Apr 20 '18 at 18:27
52
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
Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
DevOops
  • 943
  • 2
  • 10
  • 21
  • 1
    I got this error: zipimport.ZipImportError: can't decompress data; zlib not available... do you know why this happens? – SoldierCorp Jan 08 '16 at 19:33
  • Sounds like you don't have zlib-devel or zlib, depending. Can you try installing it with your package manager? sudo yum install zlib or sudo apt-get install zlib. I hope that helps. – DevOops Jan 08 '16 at 21:03
  • I'm also facing the problem same as @SoldierCorp but when I try to install `zlib` it says `Package zlib-1.2.3-29.el6.x86_64 already installed and latest version` any idea what's happening? – Mostafiz Rahman Apr 16 '16 at 15:39
  • If you are installing on OS X 10.11, you may try running the xcode setup again: xcode-select --install – DevOops Apr 16 '16 at 16:26
  • I'm using centos 6.7 – Mostafiz Rahman Apr 16 '16 at 16:31
  • Piping from the internet into python is just as bad as piping from the internet into bash. – carlwgeorge Jul 21 '16 at 20:10
  • Read the comment at the top of `https://bootstrap.pypa.io/get-pip.py` before installing with get-pip.py and make your decision after that. – Armut May 22 '19 at 21:49
  • FYI: ERROR: This script does not work on Python 3.4 The minimum supported Python version is 3.6. Please use https://bootstrap.pypa.io/pip/3.4/get-pip.py instead. – Gary Apr 05 '21 at 21:22
16

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.

Dave
  • 3,834
  • 2
  • 29
  • 44
  • 2
    Much appreciated. For those who need this the wheels are available here for setuptools https://pypi.python.org/simple/setuptools/ and here for pip https://pypi.python.org/simple/pip/ – yoshiwaan Mar 18 '16 at 17:49
  • Unfortunately, editing ensurepip's __init__.py file causes RPM verification failure, and will also be overwritten on package updates. – carlwgeorge Jul 21 '16 at 20:09
  • 2
    I would _really_ love to know what the heck their rationale was for causing this mess is. I'm telling myself there must be a good reason... – xenithorb Sep 06 '16 at 04:36
  • @xenithorb, the rationale likely was to package pip separately - since Fedora also has `python3-pip`. The python3 on EPEL project apparently is still work in progress. – maxschlepzig Oct 08 '16 at 18:16
  • EPEL (extra-packages for enterprise linux) `python36` now works with `python3.6 -m ensurepip`. – Kevin Apr 02 '19 at 17:12
9

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.

carlwgeorge
  • 627
  • 5
  • 13
  • 1
    Not sure why anyone would downvote this answer. Thanks for bringing IUS to our attention. – Dave Aug 19 '16 at 19:39
  • Regarding the downvote, it would have been helpful to explain the "broken" comment on EPEL installs. I too discovered IUS today from a related search and any mention of that on answer here deserves an upvote. – Mark Edington Feb 15 '17 at 21:23
  • 1
    @MarkEdington I edited the answer to add a link to https://bugzilla.redhat.com/show_bug.cgi?id=1263057. – carlwgeorge Feb 15 '17 at 21:44
  • 1
    This issue was fixed with python34-3.4.5-4 – DrStrangepork Jul 13 '17 at 17:06
8
yum install python34-pip

pip3.4 install foo

You will likely need the EPEL repositories installed:

yum install -y epel-release

some bits flipped
  • 2,592
  • 4
  • 27
  • 42
Shen Yu
  • 147
  • 1
  • 4
3

Update 2019

I tried easy_install at first but it doesn't install packages in a clean and intuitive way. Also when it comes time to remove packages it left a lot of artifacts that needed to be cleaned up.

sudo yum install epel-release
sudo yum install python34-pip
pip install package

Was the solution that worked for me, it installs "pip3" as pip on the system. It also uses standard rpm structure so it clean in its removal. I am not sure what process you would need to take if you want both python2 and python3 package manager on your system.

Aundre
  • 383
  • 4
  • 7
1

Below are the steps I followed to install python34 and pip

yum update -y
yum -y install yum-utils
yum -y groupinstall development
yum -y install https://centos7.iuscommunity.org/ius-release.rpm
yum makecache
yum -y install python34u  python34u-pip
python3.6 -v
echo "alias python=/usr/bin/python3.4" >> ~/.bash_profile
source ~/.bash_profile
pip3 install --upgrade pip

# if yum install python34u-pip doesnt work, try 

curl https://bootstrap.pypa.io/get-pip.py | python
jhpratt
  • 6,841
  • 16
  • 40
  • 50
0

There is a easy way of doing this by just using easy_install (A Setuptools to package python librarie).

  • Assumption. Before doing this check whether you have python installed into your Centos machine (at least 2.x).

  • Steps to install pip.

    1. So lets do install easy_install,

      sudo yum install python-setuptools python-setuptools-devel

    2. Now lets do pip with easy_install,

      sudo easy_install pip

That's Great. Now you have pip :)

Sundar Gsv
  • 627
  • 7
  • 7
0

Figure out what version of python3 you have installed:

yum search pip

and then install the best match. Use reqoquery to find name of resulting pip3.e.g

repoquery -l python36u-pip

tells me to use pip3.6 instead of pip3

gerardw
  • 5,822
  • 46
  • 39
-4

On CentOS 7, the pip version is pip3.4 and is located here:

/usr/local/bin/pip3.4
coatless
  • 20,011
  • 13
  • 69
  • 84
  • 2
    Files in /usr/local/bin are unlikely to be packaged by RHEL/CentOS. Can you successfully execute "rpm -qf /usr/local/bin/pip3.4" ? If this works, "rpm -qi " on the output... who is the packager? – Jeff W May 24 '16 at 01:46