I\'m trying to install version 1.2.2 of the MySQL_python adaptor, using a fresh virtualenv created with the --no-site-packages
option. The current version shown
Since this appeared to be a breaking change introduced in version 10 of pip, I downgraded to a compatible version:
pip install 'pip<10'
This command tells pip to install a version of the module lower than version 10. Do this in a virutalenv so you don't screw up your site installation of Python.
I recently ran into an issue when using pip
's -I
flag that I wanted to document somewhere:
-I
will not uninstall the existing package before proceeding; it will just install it on top of the old one. This means that any files that should be deleted between versions will instead be left in place. This can cause weird behavior if those files share names with other installed modules.
For example, let's say there's a package named package
. In one of package
s files, they use import datetime
. Now, in package@2.0.0
, this points to the standard library datetime
module, but in package@3.0.0
, they added a local datetime.py
as a replacement for the standard library version (for whatever reason).
Now lets say I run pip install package==3.0.0
, but then later realize that I actually wanted version 2.0.0
. If I now run pip install -I package==2.0.0
, the old datetime.py
file will not be removed, so any calls to import datetime
will import the wrong module.
In my case, this manifested with strange syntax errors because the newer version of the package added a file that was only compatible with Python 3, and when I downgraded package versions to support Python 2, I continued importing the Python-3-only module.
Based on this, I would argue that uninstalling the old package is always preferable to using -I
when updating installed package versions.
To install a specific python package version whether it is the first time, an upgrade or a downgrade use:
pip install --force-reinstall MySQL_python==1.2.4
MySQL_python version 1.2.2 is not available so I used a different version. To view all available package versions from an index exclude the version:
pip install MySQL_python==
Sometimes, the previously installed version is cached.
~$ pip install pillow==5.2.0
It returns the followings:
Requirement already satisfied: pillow==5.2.0 in /home/ubuntu/anaconda3/lib/python3.6/site-packages (5.2.0)
We can use --no-cache-dir together with -I to overwrite this
~$ pip install --no-cache-dir -I pillow==5.2.0
You can even use a version range with pip install
command. Something like this:
pip 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:
pip install 'stevedore>=1.3.0,<1.4.0' --force-reinstall
One way, as suggested in this post, is to mention version in pip
as:
pip install -Iv MySQL_python==1.2.2
i.e. Use ==
and mention the version number to install only that version. -I, --ignore-installed
ignores already installed packages.