介绍一种pip自动更新Python包的方法。
思路:使用Python脚本读取当前pip列表,再逐个更新
import os
# 升级pip
command = 'python -m pip install --upgrade pip'
os.system(command)
# 获取pip列表
command = 'pip list'
cmd_data = os.popen(command)
# 升级包
contents = cmd_data.readlines()[2:]
for line in contents:
package = line.split(" ")[0]
print()
print(f'检查更新包: {package}')
os.system(f'pip install {package} --upgrade')
print("更新完毕")
标签:package,print,command,自动更新,pip,os
From: https://www.cnblogs.com/mastermao/p/16862465.html