Python 我可以强制 pip 重新安装当前版本吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19548957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I force pip to reinstall the current version?
提问by orome
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?
我遇到过当前版本的软件包似乎无法正常工作并需要重新安装的情况。但pip install -U
不会触及已经是最新的包。我看到了如何通过首先卸载(使用pip uninstall
)然后安装来强制重新安装,但是有没有办法在一个步骤中简单地强制“更新”到名义上的当前版本?
采纳答案by KGo
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).
忽略已安装的软件包(而是重新安装)。
回答by anemes
--force-reinstall
doesn't appear to force reinstall using python2.7 with pip-1.5
似乎没有使用 python2.7 和 pip-1.5 强制重新安装
I've had to use
我不得不使用
--no-deps --ignore-installed
回答by Finn ?rup Nielsen
You might want to have all three options: --upgrade
and --force-reinstall
ensures reinstallation, while --no-deps
avoids reinstalling dependencies.
您可能希望拥有所有三个选项:--upgrade
并--force-reinstall
确保重新安装,同时--no-deps
避免重新安装依赖项。
$ 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.
否则你可能会遇到pip开始重新编译Numpy或其他大包的问题。
回答by Davy
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:
如果你想重新安装requirements.txt文件中指定的包,而不升级,那么只需重新安装requirements.txt文件中指定的特定版本:
pip install -r requirements.txt --ignore-installed
回答by Daniel
If you have a text file with loads of packages you need to add the -rflag
如果你有一个包含大量包的文本文件,你需要添加-r标志
pip install --upgrade --no-deps --force-reinstall -r requirements.txt
回答by mrgloom
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"
回答by Jorge Cribb
In the case you need to force the reinstallation of pipitself you can do:
如果您需要强制重新安装pip本身,您可以执行以下操作:
python -m pip install --upgrade --force-reinstall pip