Can I force pip to reinstall the current version?
To reinstall a Python package, you can use --force-reinstall
and --no-cache-dir
options in pip:
Replace <package>
with the package's name to get a fresh installation that doesn't use cached files.
Package reinstallation for troublers
When reinstalling a specific version of a package, you specify the version number with ==
:
It's like a time machine, going back to <current_version>
to reinstall it.
The "I don't care it's already installed" flag
Sometimes you need to force reinstall the current version. That's where --ignore-installed
comes in handy:
This command is the package manager equivalent of “I don’t care if it’s there, get me a new one”.
Safe reinstalling in virtual environments
Virtual environments are safer to manage dependencies. To force reinstall in virtual environments without messing up with system packages, the command goes like this:
Keep the dependencies in check
For a package with heavy dependencies, like our friend Numpy, you might not want to drop the whole universe. You can use the --no-deps
flag:
A fresh start for multiple packages
When you have a requirements.txt
file and need to reinstall all the listed packages, add --ignore-installed trigger:
This is like saying, “Hey, packages, it’s not you, it’s me. I need a fresh start.”
sudo: the double-edged sword
Running pip with sudo
needs caution. You might think you're the king/queen of the world, but you might end up installing packages system-wide which is not always "the best idea ever":
Reinstalling all: the nuclear option
Meeting issues? Angular isn't React? Consider starting anew with a comprehensive reinstall of all packages:
No-cache, no-problem
To avoid using cached packages, utilize --no-cache-dir
. This confirms you're getting the package from the source, fresh and untouched.
Was this article helpful?