网上搜到的大部分是这个版本
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)
本文提供了一个Python脚本,用于批量升级环境中安装的所有Python包。通过调用pip的get_installed_distributions()函数获取已安装的包列表,然后逐一进行升级。
2万+

被折叠的 条评论
为什么被折叠?



