python3 批量更新包,解决Specify --upgrade to force replacement

# 当前pip 22.1.2
# 需要安装 setuptools
import pkg_resources
from subprocess import call

packages = [dist.project_name for dist in pkg_resources.working_set]
# 使用豆瓣源更新
call("pip install -i https://pypi.douban.com/simple/ --upgrade " + ' '.join(packages), shell=True)

你可能感兴趣的:(笔记,python,开发语言)