Install a Module Using Pip for Specific Python Version

Install a module using pip for specific python version

Use a version of pip installed against the Python instance you want to install new packages to.

In many distributions, there may be separate python2.6-pip and python2.7-pip packages, invoked with binary names such as pip-2.6 and pip-2.7. If pip is not packaged in your distribution for the desired target, you might look for a setuptools or easyinstall package, or use virtualenv (which will always include pip in a generated environment).

pip's website includes installation instructions, if you can't find anything within your distribution.

How to install a package for a specific Python version on Windows 10?

The golden rule when one wants to access one of the multiple software versions (applies to any software (other than Python), on any OS) existing on a machine: use absolute paths.

There are multiple ways of pip installing (especially when involving VEnvs):

  1. Run PIP directly - most frequently used (pip install --upgrade pyaudio)

  2. Run python -m pip (python -m pip install --upgrade pyaudio)

  3. Run other convenience wrappers (Py (Win specific): [Python.Docs]: Using Python on Windows - From the command-line) (py -3.6 -m pip install --upgrade pyaudio)

But the form that I prefer (as it will always work - because it doesn't rely on the PATH environment variable), is the 2nd one:

"${PATH_TO_YOUR_PYTHON_3_6}" -m pip install --upgrade pyaudio

where ${PATH_TO_YOUR_PYTHON_3_6} is just a placeholder for the actual Python 3.6 executable path (e.g. %ProgramFiles%\Python 3.6\python.exe).
Check [Python.Docs]: Using Python on Windows - Installing Without UI for more details regarding install paths.

Generalizing:

"${PATH_TO_PYTHON_EXECUTABLE}" -m pip install ${PACKAGE_NAME}

where ${PACKAGE_NAME} is (obviously) the package name, and ${PATH_TO_PYTHON_EXECUTABLE} (using v3.9 as an example) can be (from my machines):

  • Win:

    • %ProgramFiles%\Python 3.9\python.exe

    • E:\Work\Dev\VEnvs\py_pc064_03.09_test0\Scripts\python.exe

    • F:\Install\pc064\Anaconda\Anaconda\Version\python.exe

  • Nix:

    • /usr/bin/python3.9

    • /opt/qti-aic/dev/python/qaic-env/bin/python

When not sure about an executable location (actually not limited to executables), that can be checked:

  • Win: [MS.Docs]: where

  • Nix: [Die.Linux]: which(1) (man which). Worth mentioning aliases: [Man7]: ALIAS(1P) (man alias)

Dealing with multiple Python versions and PIP?

The current recommendation is to use python -m pip, where python is the version of Python you would like to use. This is the recommendation because it works across all versions of Python, and in all forms of virtualenv. For example:

# The system default python:
$ python -m pip install fish

# A virtualenv's python:
$ .env/bin/python -m pip install fish

# A specific version of python:
$ python-3.6 -m pip install fish

Previous answer, left for posterity:

Since version 0.8, Pip supports pip-{version}. You can use it the same as easy_install-{version}:

$ pip-2.5 install myfoopackage
$ pip-2.6 install otherpackage
$ pip-2.7 install mybarpackage

EDIT: pip changed its schema to use pipVERSION instead of pip-VERSION in version 1.5. You should use the following if you have pip >= 1.5:

$ pip2.6 install otherpackage
$ pip2.7 install mybarpackage

Check https://github.com/pypa/pip/pull/1053 for more details


References:

  • https://github.com/pypa/pip/issues/200
  • http://www.pip-installer.org/docs/pip/en/0.8.3/news.html#id4

    https://pip.pypa.io/en/stable/news/#v0-8 or

    https://web.archive.org/web/20140310013920/http://www.pip-installer.org:80/docs/pip/en/0.8.3/news.html#id4

How to install a package for specific python version

python -m pip install package

python3 -m pip install package

This is how you would do it using pip for v2 and v4 respectively.

Installing specific package version with pip

TL;DR:

  • pip install -Iv (i.e. pip install -Iv MySQL_python==1.2.2)

What these options mean:

  • -I stands for --ignore-installed which will ignore the installed packages, overwriting them.
  • -v is for verbose. You can combine for even more verbosity (i.e. -vv) up to 3 times (e.g. -Ivvv).

For more information, see pip install --help

First, I see two issues with what you're trying to do. Since you already have an installed version, you should either uninstall the current existing driver or use pip install -I MySQL_python==1.2.2

However, you'll soon find out that this doesn't work. If you look at pip's installation log, or if you do a pip install -Iv MySQL_python==1.2.2 you'll find that the PyPI URL link does not work for MySQL_python v1.2.2. You can verify this here: http://pypi.python.org/pypi/MySQL-python/1.2.2

The download link 404s and the fallback URL links are re-directing infinitely due to sourceforge.net's recent upgrade and PyPI's stale URL.

So to properly install the driver, you can follow these steps:

pip uninstall MySQL_python
pip install -Iv http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.2/MySQL-python-1.2.2.tar.gz/download


Related Topics



Leave a reply



Submit