[python] Can I force pip to reinstall the current version?

I've come across situations where a current version of a package seems not to be working and requires reinstallation. But pip install -U won't touch a package that is already up-to-date. I see how to force a reinstallation by first uninstalling (with pip uninstall) and then installing, but is there a way to simply force an "update" to a nominally current version in a single step?

This question is related to python pip packages

The answer is


If you want to reinstall packages specified in a requirements.txt file, without upgrading, so just reinstall the specific versions specified in the requirements.txt file:

pip install -r requirements.txt --ignore-installed

sudo pip3 install --upgrade --force-reinstall --no-deps --no-cache-dir <package-name>==<package-version>

Some relevant answers:

Difference between pip install options "ignore-installed" and "force-reinstall"


You might want to have all three options: --upgrade and --force-reinstall ensures reinstallation, while --no-deps avoids reinstalling dependencies.

$ sudo pip install --upgrade --no-deps --force-reinstall <packagename>

Otherwise you might run into the problem that pip starts to recompile Numpy or other large packages.


--force-reinstall

doesn't appear to force reinstall using python2.7 with pip-1.5

I've had to use

--no-deps --ignore-installed

In the case you need to force the reinstallation of pip itself you can do:

python -m pip install --upgrade --force-reinstall pip

If you have a text file with loads of packages you need to add the -r flag

pip install --upgrade --no-deps --force-reinstall -r requirements.txt

Examples related to python

programming a servo thru a barometer Is there a way to view two blocks of code from the same file simultaneously in Sublime Text? python variable NameError Why my regexp for hyphenated words doesn't work? Comparing a variable with a string python not working when redirecting from bash script is it possible to add colors to python output? Get Public URL for File - Google Cloud Storage - App Engine (Python) Real time face detection OpenCV, Python xlrd.biffh.XLRDError: Excel xlsx file; not supported Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation

Examples related to pip

How to fix error "ERROR: Command errored out with exit status 1: python." when trying to install django-heroku using pip "E: Unable to locate package python-pip" on Ubuntu 18.04 How to Install pip for python 3.7 on Ubuntu 18? What is the meaning of "Failed building wheel for X" in pip install? Could not install packages due to an EnvironmentError: [Errno 13] How do I install Python packages in Google's Colab? Conda version pip install -r requirements.txt --target ./lib pip: no module named _internal AttributeError: Module Pip has no attribute 'main' Error after upgrading pip: cannot import name 'main'

Examples related to packages

How to install Python packages from the tar.gz file without using pip install Package name does not correspond to the file path - IntelliJ Can I force pip to reinstall the current version? The import android.support cannot be resolved How to solve java.lang.NoClassDefFoundError? How to list all installed packages and their versions in Python? Importing packages in Java Check for installed packages before running install.packages() How do I find a list of Homebrew's installable packages? Installing a local module using npm?