Can I force pip to reinstall the current version?

Question:

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?

Asked By: orome

||

Answers:

pip install --upgrade --force-reinstall <package>

When upgrading, reinstall all packages even if they are already up-to-date.

pip install -I <package>
pip install --ignore-installed <package>

Ignore the installed packages (reinstalling instead).

Answered By: KGo
--upgrade --force-reinstall

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

I’ve had to use

--no-deps --ignore-installed
Answered By: anemes

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.

Answered By: Finn Årup Nielsen

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
Answered By: Davy

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
Answered By: Daniel
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"

Answered By: mrgloom

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

python -m pip install --upgrade --force-reinstall pip
Answered By: Jorge Cribb

If you work on MacOS and are using Homebrew, run:

/opt/homebrew/opt/[email protected]/bin/python3.11 -m pip install --upgrade pip

of course use the appropriate path for your version

Answered By: RaamEE

I had a Jupyter notebook open using the python kernel that has the package loaded already. I closed that notebook and tried again and it worked.

Answered By: Worthy7
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.