[英]Uninstall and re-install pip package from python module
I have uninstalled package 'setuptools' from python using following pip function 我使用以下pip函数从python中卸载了包'setuptools'
import pip
pip.main(['uninstall','--yes','setuptools'])
When, I tried to re-install the same package again using below command, it throws the following error message 当我尝试使用下面的命令再次重新安装相同的包时,它会抛出以下错误消息
pip.main(['install','setuptools'])
Error: 错误:
Requirement already satisfied (use --upgrade to upgrade): setuptools in c:\\python27\\lib\\site-packages
Is there any option to overcome this ? 有没有办法克服这个问题? Thanks in advance :)
提前致谢 :)
Yes, --ignore-installed
. 是的, -
--ignore-installed
。 For more info: pip install --help
which explains: 有关更多信息:
pip install --help
解释:
-U, --upgrade Upgrade all specified packages to the newest
available version. This process is recursive
regardless of whether a dependency is already
satisfied.
--force-reinstall When upgrading, reinstall all packages even if
they are already up-to-date.
-I, --ignore-installed Ignore the installed packages (reinstalling
instead).
Besides, I tried it with Python 3.4. 此外,我尝试使用Python 3.4。 Of the above options, only
pip install --ignore-installed
would install a previously installed package. 在上述选项中,只有
pip install --ignore-installed
会安装以前安装的软件包。
Uninstall won't take effect until next time python is started. 在下次启动python之前,卸载不会生效。 So to uninstall and reinstal what you could do is divide your code into 2 files.
因此,要卸载并重新安装可以执行的操作,请将代码分成2个文件。
File "main.py": 文件“main.py”:
import pip
import os
pip.main(['uninstall','--yes','setuptools'])
os.system('python install_setuptools.py')
File "install_setuptools.py": 文件“install_setuptools.py”:
import pip
pip.main(['install','setuptools'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.