习惯使用一个小的脚本更新所有pip包:
import pip
from subprocess import call
for dist in get_installed_distributions():
call("sudo install --upgrade " + dist.project_name, shell=True)
可是最近pip更新到pip 10.0.1后,再用这个脚本更新会报错。
Traceback (most recent call last):
File "pipupdate.py", line 5, in <module>
for dist in pip.get_installed_distributions():
AttributeError: 'module' object has no attribute 'get_installed_distributions'
查了下资料,需要在脚本中加入一些东西才能正常运行。
新的脚本如下:
import pip
# pip V10.0.0以上版本需要导入下面的包
from pip._internal.utils.misc import get_installed_distributions
from subprocess import call
from time import sleep
for dist in get_installed_distributions():
call("pip install --upgrade " + dist.project_name, shell=True)
然后就可能正常批量更新了。