Alternatively, since pip itself is written in python, you can just call it with the python version you want to install the package for:
Copypython2.7 -m pip install foo
Answer from Turion on Stack OverflowAlternatively, since pip itself is written in python, you can just call it with the python version you want to install the package for:
Copypython2.7 -m pip install foo
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.
Update: In the modern (2020s) world, python -m pip is the right way to do this, where python can be replaced with whichever interpreter you choose.
python - Installing specific package version with pip - Stack Overflow
How do I choose what python version pip installs packages to.
How to use pip install to install a "specific version" of a library ?
Are python packages tied to a specific python version?
Videos
TL;DR:
Update as of 2022-12-28:
pip install --force-reinstall -v
For example: pip install --force-reinstall -v "MySQL_python==1.2.2"
What these options mean:
--force-reinstallis an option to reinstall all packages even if they are already up-to-date.-vis for verbose. You can combine for even more verbosity (i.e.-vv) up to 3 times (e.g.--force-reinstall -vvv).
Thanks to @Peter for highlighting this (and it seems that the context of the question has broadened given the time when the question was first asked!), the documentation for Python discusses a caveat with using -I, in that it can break your installation if it was installed with a different package manager or if if your package is/was a different version.
Original answer:
pip install -Iv(i.e.pip install -Iv MySQL_python==1.2.2)
What these options mean:
-Istands for--ignore-installedwhich will ignore the installed packages, overwriting them.-vis 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:
Copypip 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
You can even use a version range with pip install command. Something like this:
Copypip install 'stevedore>=1.3.0,<1.4.0'
And if the package is already installed and you want to downgrade it add --force-reinstall like this:
Copypip install 'stevedore>=1.3.0,<1.4.0' --force-reinstall
You have two options, but either way, you need to get easy_install-3.2. Since it doesn't seem to be packaged, you have to install it yourself. Fortunately that's easy. And you should also get python3-pkg-resources, which is packaged:
sudo apt-get install python3-pkg-resources
wget http://python-distribute.org/distribute_setup.py
sudo python3 distribute_setup.py
Now you can just use easy_install-3.2 to install Pyramid, or go ahead and install pip in Python3.
OPTION 1:
sudo easy_install-3.2 pyramid
OPTION 2:
sudo easy_install-3.2 pip
sudo pip-3.2 install pyramid
Alternatively, if you want to install specific version of the package with the specific version of python, this is the way
sudo python2.7 -m pip install pyudev=0.16
If the "=" doesnt work, use "=="
sudo python2.7 -m pip install pyudev=0.16
Ouput: Invalid requirement: 'pyudev=0.16' = is not a valid operator. Did you mean == ?
sudo python2.7 -m pip install pyudev==0.16
works fine
I have multiple python instances and virtual environments. But I want pip to install packages onto a specific version. Preferably to "set it to default" or something. How can I do that?
How do I specify to pip installer that I want a specific version of a library. And how do I rollback (uninstall a library if I make a mistake)?
I am using Python 3.9.9 in my dev environment and want this same version in my Linux Buildozer.
Here's what I have installed in my dev environment, and want it mirrored in my Buildozer environment:
Python 3.9.9 certifi==2021.10.8 charset-normalizer==2.0.7 docutils==0.18 idna==3.3 Kivy==2.0.0 kivy-deps.angle==0.3.0 kivy-deps.glew==0.3.0 kivy-deps.sdl2==0.3.1 Kivy-Garden==0.1.4 kivymd @ https://github.com/kivymd/KivyMD/archive/master.zip Pillow==8.4.0 plyer==2.0.0 Pygments==2.10.0 pypiwin32==223 python-percentage==1.0.0 pywin32==302 requests==2.26.0 urllib3==1.26.7
(I am installing a virtual machine on my PC, and Buildozer under Linux in that.)