It is common for library files to get corrupted with time for a programming language. In such cases, it may break the code in inexplicable ways. To resolve such issues, the library files need to be reinstalled a new to fix the problems. Here, we will learn how to force pip to reinstall the current version. There could be two situations in which the reinstall of the current version is required:
- Reinstalling the current version of the pip
- Reinstalling the current version of a library
Since all of this could be performed from the command line, only the statements producing the effects would be described, and if you’re using a pip version that is less than 10.0, it’s time to update pip using the following command:
pip install --upgrade pip
Reinstalling the current version of the pip
It may be required that pip by itself may be needed to be reinstalled. Where all the previously mentioned switches are used. Just the pip library is replaced at the position of the package name (as pip by itself is also a package). The command for which would be:
pip install --upgrade --force-reinstall pip
Example:
In the following example, pip would be reinstalled:
python -m pip install --upgrade --force-reinstall pip
Reinstalling the current version of a library
To uninstall an installed library from your Python distribution, the command would be:
pip install --upgrade --no-deps --force-reinstall <package_name>
Where
--upgrade: Upgrade all specified packages to the newest available version.
- –no-deps: Don’t install package dependencies.
- –force-reinstall: Reinstall all packages even if they are already up-to-date.
- <package_name> is the name of the package to be installed.
Note: *The reason for the inclusion of –no-deps switch is done assuming that the dependencies don’t require a reinstall.
Example:
To reinstall the library NumPy, the command would be:
pip install --upgrade --no-deps --force-reinstall numpy
Reinstalling without removing the current versions
If, for some reason, you want to re-install <corrupted package> and all its dependencies without first removing the current versions, you can run:
pip install --ignore-installed <corrupted package>
Related Articles: Python PIP – Lazyroar