習(xí)慣使用一個(gè)小的腳本更新所有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后储狭,再用這個(gè)腳本更新會(huì)報(bào)錯(cuò)莺匠。
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'
查了下資料腥光,需要在腳本中加入一些東西才能正常運(yùn)行罗珍。
新的腳本如下:
import pip
# pip V10.0.0以上版本需要導(dǎo)入下面的包
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)
然后就可能正常批量更新了。