问题:我可以强迫pip重新安装当前版本吗?

我遇到过以下情况:当前版本的软件包似乎无法正常工作,需要重新安装。但是,pip install -U不要触摸已经是最新的软件包。我看到了如何通过先卸载(使用pip uninstall)然后安装来强制进行重新安装,但是有没有办法在一个步骤中简单地将“更新”强制为名义上的当前版本?

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?


回答 0

pip install --upgrade --force-reinstall <package>

升级时,请重新安装所有软件包,即使它们已经是最新的。

pip install -I <package>
pip install --ignore-installed <package>

忽略已安装的软件包(改为重新安装)。

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


回答 1

您可能希望拥有所有三个选项:--upgrade--force-reinstall确保重新安装,同时--no-deps避免重新安装依赖项。

$ sudo pip install --upgrade --no-deps --force-reinstall <packagename>

否则,您可能会遇到pip开始重新编译Numpy或其他大型软件包的问题。

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.


回答 2

如果要重新安装Requirements.txt文件中指定的软件包而不进行升级,那么只需重新安装Requirements.txt文件中指定的特定版本:

pip install -r requirements.txt --ignore-installed

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

回答 3

--force-reinstall

似乎没有强制使用python2.7和pip-1.5重新安装

我不得不用

--no-deps --ignore-installed
--force-reinstall

doesn’t appear to force reinstall using python2.7 with pip-1.5

I’ve had to use

--no-deps --ignore-installed

回答 4

如果您的文本文件包含大量软件包,则需要添加-r标志

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

If you have a text file with loads of packages you need to add the -r flag

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

回答 5

如果您需要强制重新安装pip本身,则可以执行以下操作:

python -m pip install --upgrade --force-reinstall pip

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

python -m pip install --upgrade --force-reinstall pip

回答 6

sudo pip3 install --upgrade --force-reinstall --no-deps --no-cache-dir <package-name>==<package-version>

一些相关的答案:

点安装选项“忽略安装”和“强制重新安装”之间的区别

sudo pip3 install --upgrade --force-reinstall --no-deps --no-cache-dir <package-name>==<package-version>

Some relevant answers:

Difference between pip install options “ignore-installed” and “force-reinstall”


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。