Can I force pip to reinstall the current version?

713,094

Solution 1

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).

Solution 2

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.

Solution 3

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

Solution 4

--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

Solution 5

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

python -m pip install --upgrade --force-reinstall pip
Share:
713,094
orome
Author by

orome

"I mingle the probable with the necessary and draw a plausible conclusion from the mixture."

Updated on July 08, 2022

Comments

  • orome
    orome almost 2 years

    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?

  • Keegan Quinn
    Keegan Quinn over 10 years
    You must specify --upgrade in addition to --force-reinstall, or it won't have any effect.
  • radtek
    radtek almost 10 years
    Any way to force an overwrite when using --target= flag? none of these worked for me. I get the destination path already exists error.
  • The Red Pea
    The Red Pea over 8 years
    @KeeganQuinn do you think that's what Karan meant by "When upgrading"...? I suppose so. But your clarification certainly helps me.
  • orodbhen
    orodbhen almost 6 years
    This also works for offline installs, while the excepted answer doesn't.
  • Assil Ksiksi
    Assil Ksiksi over 5 years
    This is a better solution for packages with a large number of dependencies that do not need to be reinstalled.
  • gseattle
    gseattle over 5 years
    What if I want to make a change in zipline which is installed in the process of pip install pipeline-live, and simply pick up my change in zipline?
  • cjerdonek
    cjerdonek over 5 years
    Including --upgrade when --force-reinstall is being used shouldn't be needed as of pip 10.0, FYI: github.com/pypa/pip/issues/1139
  • mrgloom
    mrgloom almost 5 years
    While installing it saying Using cached for some packages, how to force their reinstall also?
  • lcnittl
    lcnittl almost 5 years
    @mrgloom The using cachedjust means it uses source files that where cached on the last install. To force re-download use the --no-cache-dir flag.
  • mrgloom
    mrgloom almost 5 years
    sudo was crucial in my case.
  • mrgloom
    mrgloom almost 5 years
    Why we need --upgrade when we use --force-reinstall?
  • mrgloom
    mrgloom almost 5 years
    @FinnÅrupNielsen why it should upgrade current version? as I understand here we want to reinstall package. What if <package-name>==<package-version> format is used?
  • Finn Årup Nielsen
    Finn Årup Nielsen almost 5 years
    @mrgloom --force-reinstall alone does not necessarily upgrade to the current version (at least not in pip 9.0.1). There has been an upgrade according to github.com/pypa/pip/issues/1139 see cjerdonek's answer, so newer versions do not require the option.
  • WestCoastProjects
    WestCoastProjects over 4 years
    I don't want to reinstall any dependencies - only just the single package. Is this possible / how ? Ah just see from next answer seems to be --no-deps
  • ComputerScientist
    ComputerScientist over 4 years
    Why do you have sudo here??
  • smci
    smci almost 4 years
    pip install -U, for short. (and the --force-reinstall option is rarely necessary)
  • wesinat0r
    wesinat0r almost 4 years
    macOS: You shouldn't run sudo with pip on a mac . Run as admin rights user but without sudo . On Linux (Ubuntu): it makes sense to run with sudo to install for all users. Don't run sudo with --user as that will install packages under root user only.
  • jxramos
    jxramos over 3 years
    So by default all dependent projects likewise get updated too from the --upgrade flag, is that right?
  • Skippy le Grand Gourou
    Skippy le Grand Gourou over 3 years
    Note that this command also reinstalls all dependencies. Add --no-deps to avoid that, as suggested in Finn’s answer below.
  • Hektor
    Hektor about 3 years
    This does not work for updating pip itself
  • Davy
    Davy over 2 years
    And if you want to avoid using the local cache, add the option --no-cache-dir