There are two pip install
options related to reinstalling the packages, which are --ignore-installed
and --force-reinstall
.
These two options described as following in the official doc
--force-reinstall
Reinstall all packages even if they are already up-to-date.
-I, --ignore-installed
Ignore the installed packages (reinstalling instead).
It seems that they all ignore something and do the reinstallation but I cannot tell the difference between them (I can see some difference if I actually execute them ... but I cannot explain). If I search "force reinstall packages in pip", the result lists both --ignore-installed
and --force-reinstall
, which confuses me for a long time.
--force-reinstall
Before installing a package, will uninstall it first if already installed. Pretty much the same as running
pip uninstall -y dep && pip install dep
for package and its every dependency.--ignore-installed
Ignores whether the package and its deps are already installed, overwriting installed files. This means that you can have a situation where
--ignore-installed
does not uninstall a file, leaving it insite-packages
forever. Imagine you havepkgname==1.0
that provides modulespam
:and the next version
pkgname==2.0
renamedspam
toeggs
. When runningpip install pkgname==2.0 --ignore-installed
,spam.py
will not be removed, left orphaned forever until you remove it manually.Consequence
--force-reinstall
should always be preferred; use--ignore-installed
only if youknow what you're doingare sure that the reinstall will overwrite currently installed files. Otherwise, you may get obscure import errors after reinstall due to stale modules still available insys.path
.Example
Example to reproduce with the latest
pip
changes where all its packages were moved under_internal
package: create a new virtual environment and downgradepip
to version 9:If you would now upgrade
pip
to the latest version via--force-reinstall
, a clean upgrade is performed. Afterwards, you have the correct package structure with the_internal
and_vendor
:If you would do the upgrade with
--ignore-installed
instead:Upgrading
pip
with--ignore-installed
did not uninstall previous package version first, and due to new file structure, new files did not overwrite the old ones. As a consequence, old files are now orphaned and not picked up by any package; evenpip uninstall pip
will not remove the orphaned files. One would need to clean them up manually.