#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pip
# python3.7 新版本需要需要导入下面的包
from pip._internal.utils.misc import get_installed_distributions
from subprocess import call
from time import sleep
#更新pip
call("python -m pip install -i https://mirrors.aliyun.com/pypi/simple --upgrade pip")
for dist in get_installed_distributions():
# 执行后,pip默认为Python3版本
# 双版本下需要更新Python2版本的包,使用py2运行,并将pip修改成pip2
#call("pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple/ --upgrade " + dist.project_name, shell=True)
call("pip install -i https://mirrors.aliyun.com/pypi/simple --upgrade " + dist.project_name, shell=True)
复制以上代码,存为update.py文件。
然后在命令行运行 python update.py 实现自动更新
本文提供了一个Python脚本,用于自动更新已安装的所有Python包至最新版本。通过调用pip工具并利用阿里云的镜像源,确保了更新过程的高效与稳定。
1430

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



