PIP
Python
Package Manager
Reinstall
Programming

How to force pip to reinstall a package (pip install --force-reinstall)

Codemia Knowledge Hub ·

Yes. pip install --force-reinstall <package> uninstalls a package and installs it again, which fixes corrupted installations, missing files and broken compiled extensions. Without a version specifier pip may pick the latest release instead of the one you have, so to reinstall the current version, pin it: pip install --force-reinstall requests==2.31.0.

The basic command

bash
pip install --force-reinstall requests

It does three things in order:

  1. Uninstalls the existing requests package.
  2. Fetches the package from PyPI (or your configured index), or from pip's local cache if a cached wheel exists.
  3. Installs it fresh.

Check what you have first so you know which version to pin:

bash
# Show package details
pip show requests

Output:

 
1Name: requests
2Version: 2.31.0
3Location: /home/user/.venv/lib/python3.12/site-packages
4Requires: certifi, charset-normalizer, idna, urllib3

Reinstall flags compared

FlagWhat it doesRe-downloads?Reinstalls deps?Use when
--force-reinstallUninstalls and reinstalls the package and all its dependenciesYesYesCorrupted install, broken C extensions
--force-reinstall --no-depsReinstalls only the target package, leaves dependencies aloneYesNoOnly the target package is broken
--ignore-installedInstalls on top of existing files without uninstalling firstYesNoQuick overwrite, virtual env issues
--no-cache-dir --force-reinstallForce reinstall without using the local cacheYes (from network)YesCached wheel is corrupted

Reinstall a specific version

bash
pip install --force-reinstall requests==2.28.0

Reinstall without touching dependencies

bash
pip install --force-reinstall --no-deps numpy

This is the most common real-world form. By default --force-reinstall also reinstalls every dependency, which can take minutes and break working packages with pinned versions. If only numpy is broken, there is no reason to reinstall anything else.

Reinstall and bypass the cache

bash
pip install --force-reinstall --no-cache-dir pandas

pip stores wheels in a cache directory and reuses them. If the problem is a corrupted download, reinstalling from cache puts back the same broken file, so --no-cache-dir forces a fresh download.

Reinstall from a requirements file

bash
pip install --force-reinstall -r requirements.txt

This reinstalls every package in the file, which is useful when setting up a fresh virtual environment from a known-good requirements file.

Typical cases where a reinstall fixes things

Corrupted package after an interrupted install

bash
1$ python -c "import pandas"
2ImportError: cannot import name 'DataFrame' from 'pandas'
3
4$ pip install --force-reinstall --no-deps pandas
5Successfully installed pandas-2.2.0
6
7$ python -c "import pandas; print(pandas.__version__)"
82.2.0

C extension built for a different Python version

This happens when you upgrade Python (e.g., 3.11 to 3.12) but reuse the same virtual environment:

bash
1$ python -c "import numpy"
2ImportError: numpy.core._multiarray_umath failed to import
3
4$ pip install --force-reinstall numpy
5# Downloads and compiles numpy for the current Python version
6Successfully installed numpy-1.26.4

Compiled packages broken by a system update

After an OS update or libc upgrade, compiled packages may break:

bash
pip install --force-reinstall --no-cache-dir cryptography

Reinstalling from a local wheel

bash
pip install --force-reinstall ./dist/mypackage-1.0.0-py3-none-any.whl

Reinstalling an editable (development) install

bash
pip install --force-reinstall -e .

This refreshes entry points and package metadata while keeping editable mode. Leave out -e and pip converts the editable install into a regular one, which breaks your development workflow.

Finding broken dependencies first

bash
1# List all installed packages
2pip list
3
4# Check for broken packages
5pip check

pip check reports dependency conflicts. If it finds any, a targeted --force-reinstall of the conflicting package often resolves them.

--force-reinstall vs uninstall then install

ApproachAtomic?Handles compiled cacheReinstalls deps
--force-reinstallYes (single command)Uses cache unless --no-cache-dirYes (unless --no-deps)
uninstall + installNo (two commands)Uses cacheNo

--force-reinstall is a single transaction: if something fails midway, pip rolls back. With two separate commands you can end up with the package uninstalled and the reinstall failed.

Recreating the virtual environment

Work inside a virtual environment. If pip install --force-reinstall outside one asks for sudo on Linux or macOS, that is a sign you should be using one. Never force-reinstall packages in the macOS system Python (/usr/bin/python3); use a virtual environment or Homebrew Python.

When things are badly broken, delete the environment and rebuild it:

bash
1# Delete and recreate
2rm -rf .venv
3python -m venv .venv
4source .venv/bin/activate   # Linux/macOS
5# .venv\Scripts\activate    # Windows
6
7pip install -r requirements.txt

This guarantees a clean state. For a single broken package, --force-reinstall --no-deps is faster.


Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms