从python模块卸载并重新安装pip包

时间:2015-08-27 17:36:09

标签: python pip

我已经卸载了包' setuptools'来自python使用以下pip函数

import pip
pip.main(['uninstall','--yes','setuptools'])

当我尝试使用下面的命令再次重新安装相同的软件包时,它会抛出以下错误消息

pip.main(['install','setuptools'])

错误:

Requirement already satisfied (use --upgrade to upgrade): setuptools in c:\\python27\\lib\\site-packages

有没有办法克服这个问题?在此先感谢:)

2 个答案:

答案 0 :(得分:7)

是的,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). 解释:

pip install --ignore-installed

此外,我尝试使用Python 3.4。在上述选项中,只有<div> <div class="hero-image-download col-xs-12"> <div class="overlay"></div> <div class="hero-text-download text-center"> <h1>aspenONE Download Center</h1> <h2> Download your UPGRADE now!</h2> <p>Simply select software suite and you need to start using the latest version. It’s fast and easy</p> </div> </div> <div class="engineering-section"> <div class="engineering-section-title title-text">Engineering</div> </div> </div><!--end div--> 会安装以前安装的软件包。

答案 1 :(得分:2)

卸载在下次启动python之前不会生效。 因此,要卸载并重新安装可以执行的操作,请将代码分成2个文件。

文件&#34; main.py&#34;:

import pip
import os

pip.main(['uninstall','--yes','setuptools'])
os.system('python install_setuptools.py')

文件&#34; install_setuptools.py&#34;:

import pip

pip.main(['install','setuptools'])