How to specify the python path for pip?

7,711

Pip is bundled with Python 2.7.11 (they started adding it in 2.7.9 and 3.4), so you can use an included module to generate a short pip script:

$ /opt/python/bin/python -m ensurepip

That will make /opt/python/bin/pip, which has a shebang line pointing at /opt/python/bin/python, so you can run it when you want a pip that's associated with that particular Python installation.

If you're running an older Python, you can download get-pip.py and pass it to the Python you want to install it under:

$ wget 'https://bootstrap.pypa.io/get-pip.py'
$ /opt/python/bin/python ./get-pip.py

This will generate the same pip scripts. See the pip documentation for more information

Share:
7,711

Related videos on Youtube

willSapgreen
Author by

willSapgreen

Updated on September 18, 2022

Comments

  • willSapgreen
    willSapgreen over 1 year

    With pip installed, I am trying to install matplotlib in Ubuntu 12.04.4 LTS. I got the following error when executing "sudo pip install matplotlib" enter image description here

    I guess this is because the python version is too old (2.7.3), So I follow this discussion, How to install the latest Python version on Debian separately or upgrade?, to build the latest 2.7.11 in /opt/python/.

    My question is how to specify the newer version of python when installing matplotlib through pip?

    Or should I just use "easy_install", which is not recommended by other people?

    Thank you for precious time on my question.

  • Michael Mrozek
    Michael Mrozek over 8 years
    That works for this particular case, but the question is how to control which version of Python is used when running pip
  • Mayou36
    Mayou36 about 7 years
    -1 because you just state another way without giving an answer why it works, what it does, what the difference is (yes, there is a huge difference between the two approaches)