Last updated: Apr 10, 2024
Reading timeยท3 min
Use the --force-reinstall
option to force pip to reinstall a package, e.g.
pip install requests --force-reinstall
.
The --force-reinstall
option reinstalls the specified packages and their
dependencies, even if the packages are up to date.
# ๐๏ธ Force reinstall a package pip install requests --force-reinstall pip3 install requests --force-reinstall # ๐๏ธ Force reinstall a package and upgrade to the latest version pip install requests --force-reinstall --upgrade pip3 install requests --force-reinstall --upgrade # ๐๏ธ Force reinstall all packages in your requirements.txt file pip install -r requirements.txt --upgrade --force-reinstall
The --force-reinstall option reinstalls the specified packages even if they are already up-to-date.
--force-reinstall
option basically uninstalls the package (and its dependencies) if it's already installed and then the command installs the package.The --upgrade option upgrades the specified packages to the newest available version.
If you only want to force pip
to reinstall a package without reinstalling its
dependencies, use the
--no-deps
option.
pip install requests --force-reinstall --upgrade --no-deps
If you need to ignore one or more installed packages and reinstall them, you can
also use the --ignore-installed
option.
pip install requests --ignore-installed
The --ignore-installed option ignores the installed packages (and their dependencies) and overwrites them.
--force-reinstall
because --force-reinstall
uninstalls the package and its dependencies instead of ignoring them and overwriting them.In general, it's better to use the --force-reinstall
option because it's
cleaner, doesn't leave orphaned files and is less likely to break things.
requirements.txt
fileIf you need to reinstall all packages in your requirements.txt file, use the following command.
pip install -r requirements.txt --upgrade --force-reinstall pip3 install -r requirements.txt --upgrade --force-reinstall
The -r option is a
shorthand for --requirement
and installs from the given requirements file.
--no-cache-dir
There is also a --no-cache-dir
option that can be used to disable the cache.
pip install requests --no-cache-dir --force-reinstall --upgrade pip3 install requests --no-cache-dir --force-reinstall --upgrade
Pip's caching is turned on by default with the intent to save time on duplicate downloads and builds.
Using the --no-cache-dir option disables pip's cache.
pip
, setuptools
and wheel
If you got an error while running any of the commands in the article, try upgrading your versions of pip, setuptools and wheel.
pip install --upgrade pip setuptools wheel pip3 install --upgrade pip setuptools wheel # ๐๏ธ If you don't have pip set up in PATH python -m pip install --upgrade pip setuptools wheel python3 -m pip install --upgrade pip setuptools wheel py -m pip install --upgrade pip setuptools wheel
If you don't have pip
set up in your system's PATH environment variable, use
the python -m
command instead.
You can learn more about the related topics by checking out the following tutorials:
--no-cache-dir
option