网上搜到的大部分是这个版本
import pip
from subprocess import call
for dist in pip.get_installed_distributions():
call("pip install --upgrade " + dist.project_name, shell=True)
使用时会提示pip中没有这个函数get_installed_distributions()
更新如下
#!/usr/bin/env python
# encoding: utf-8
import pip
from subprocess import call
from pip._internal.utils.misc import get_installed_distributions
for dist in get_installed_distributions():
call("pip install --upgrade " + dist.project_name, shell=True)