11
  1. /usr/bin/python points to /usr/bin/python2.7, the old version 2.7.6 python used by my OS 14.04.

    For the old python, I wanted to install module regex:

    $ sudo python -m pip install regex
    /usr/bin/python: No module named pip
    

    So in synatpic, I installed python-pip for the old python. The above command now said:

    Python2/_regex.c:46:20: fatal error: Python.h: No such file or directory
    

    So In synaptic, I installed libpython2.7-dev. Now all works.

  2. I also installed a newer version 2.7.9 of Python to /usr/bin/local/python2.7, by compiling its source.

    How can I install pip and then install regex for my new python?

THanks.

Tim
  • 25,177

2 Answers2

11

If you install it from source you need to run:

/usr/local/bin/python2.7 -m ensurepip

This will actually install the pip application into /usr/local/bin.

techraf
  • 3,316
5

Python 2.7.9 and later (on the python2 series), and Python 3.4 and later include pip by default 1, so you may have pip already.

To install pip, securely download get-pip.py
Then run the following (which may require administrator access):
python get-pip.py

Source: https://pip.pypa.io/en/latest/installing.html

0x2b3bfa0
  • 8,780
  • 6
  • 36
  • 55
  • I installed pip in Synaptic (which is the same as sudo apt-get install python pip?), and it installed for the default old python only, not for the new self-installed python. – Tim Mar 17 '15 at 15:01
  • /usr/local/bin/python2.7 -m pip install regex returns /usr/local/bin/python2.7: No module named pip. /usr/local/bin/python2.7 --version returns Python 2.7.9. Does my python 2.7.9 miss pip? – Tim Mar 17 '15 at 15:40
  • How do you deal with Python.h: No such file or directory error when installing regex module using pip? – Tim Mar 17 '15 at 15:42
  • 2
    sudo apt-get install python-dev – 0x2b3bfa0 Mar 17 '15 at 15:45
  • that is for my old python. – Tim Mar 17 '15 at 15:46
  • I install the new python from compiling its source code. Does that by default copy head files to /usr/local/include/python2.7/? I found /usr/local/include/python2.7/Python.h – Tim Mar 17 '15 at 15:58
  • Can you update your post with the output of ls /usr/local/bin/python2.7/ – 0x2b3bfa0 Mar 17 '15 at 16:17