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?
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).
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.
sudo
was crucial in my case.
--upgrade
when we use --force-reinstall
?
sudo
to install for all users. Don't run sudo with --user
as that will install packages under root
user only.
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
--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
--upgrade
in addition to --force-reinstall
, or it won't have any effect.
In the case you need to force the reinstallation of pip itself you can do:
python -m pip install --upgrade --force-reinstall pip
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"
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
Success story sharing
using cached
just means it uses source files that where cached on the last install. To force re-download use the--no-cache-dir
flag.pip install -U
, for short. (and the--force-reinstall
option is rarely necessary)--no-deps
to avoid that, as suggested in Finn’s answer below.