How to reinstall a package even if it exists

2020-02-28 13:40发布

I want to run a pip install -r requirements.txt command;

I want to run the same command over and over again;

The issue is that requirements.txt will include some wheel files which may have the same version but different source code;

I want to make sure the package will be reinstalled, i.e. fetched again from my custom pip repo;

I am aware of this topic, but the distinction between --ignore-installed and --force-reinstall does not seem very clear to me;

I have e.g. somepack==1.1, I change the source code and I want the .whl to be fetched again from my repo when performing pip install;

Which one should I use? Should I incorporate both?

What is their difference?

The package may have the same version, e.g. somepack==1.1 or it may have incremental versions at some point. e.g. somepack==1.2

I want it to be always (re)installed;

edit: This is the help of pip which does not seem very clear to me at least in the above issue

  --force-reinstall           Reinstall all packages even if they are already up-to-date.
  -I, --ignore-installed      Ignore the installed packages (reinstalling instead).

标签: python pip
2条回答
劫难
2楼-- · 2020-02-28 14:11

With --force-reinstall, existing packages (and dependencies) are uninstalled first, while with --ignore-installed, they are not.

So --force-reinstall is the preferred choice and --ignore-installed is more of an emergency option.

Here's a sample output:

> pip install --force-reinstall ipdb
Collecting ipdb
Collecting ipython<6.0.0,>=5.0.0; python_version == "2.7" (from ipdb)
  Using cached https://<...>/ipython-5.8.0-py2-none-any.whl
Collecting setuptools (from ipdb)
<...>
Installing collected packages: six, wcwidth, prompt-toolkit, decorator, setuptools, <...>
  Found existing installation: six 1.11.0
    Uninstalling six-1.11.0:
      Successfully uninstalled six-1.11.0
  Found existing installation: wcwidth 0.1.7
    Uninstalling wcwidth-0.1.7:
      Successfully uninstalled wcwidth-0.1.7
<...>
Successfully installed backports.shutil-get-terminal-size-1.0.0 colorama-0.4.0 <...>


> pip install --ignore-installed ipdb
Collecting ipdb
Collecting ipython<6.0.0,>=5.0.0; python_version == "2.7" (from ipdb)
<...>
Collecting setuptools (from ipdb)
<...>
Installing collected packages: six, wcwidth, prompt-toolkit, decorator, setuptools, <...>
Successfully installed <...>
查看更多
Summer. ? 凉城
3楼-- · 2020-02-28 14:18

You want:

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

--force-reinstall will remove the existing packages and then install the current versions.

--ignore-installed will just overwrite the existing with the current version, but will not remove files that were deleted in the update, meaning you may have files hanging out in your library install that aren't part of the library.

--upgrade (redundant in this case), does force-reinstall for only those packages for which there is a new version.

查看更多
登录 后发表回答