快乐科研,快乐生活分享 http://blog.sciencenet.cn/u/guolingju 夫未战而庙算胜者,得算多也;未战而庙算不胜者,得算少也.多算胜少算,而况于无算乎?

博文

pip升级10.0版本后,批量更新出错解决

已有 9516 次阅读 2018-5-22 22:02 |个人分类:Python学习|系统分类:科研笔记

 习惯使用一个小的脚本更新所有pip包:

import pip
from subprocess import call

for dist in get_installed_distributions():
    call("sudo install --upgrade " + dist.project_name, shell=True)


可是最近pip更新到pip 10.0.1后,再用这个脚本更新会报错。

Traceback (most recent call last):
  File "pipupdate.py", line 5, in <module>
    for dist in pip.get_installed_distributions():  
AttributeError: 'module' object has no attribute 'get_installed_distributions'

查了下资料,需要在脚本中加入一些东西才能正常运行。新的脚本如下:


#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pip
# pip V10.0.0以上版本需要导入下面的包
from pip._internal.utils.misc import get_installed_distributions
from subprocess import call
from time import sleep

for dist in get_installed_distributions():
    call("pip install --upgrade " + dist.project_name, shell=True)


然后就可能正常批量更新了。


我只有python2,没有python3。如果两个版本都有的话,可以测试下下面的脚本。


#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pip
# pip V10.0.0以上版本需要导入下面的包
from pip._internal.utils.misc import get_installed_distributions
from subprocess import call
from time import sleep

for dist in get_installed_distributions():
    # 执行后,pip默认为Python3版本
    # 双版本下需要更新Python2版本的包,使用py2运行,并将pip修改成pip2
    call("pip install --upgrade " + dist.project_name, shell=True)


希望能节省大家一些时间。


参考文献:https://blog.csdn.net/lsp84ch80/article/details/79964655




https://blog.sciencenet.cn/blog-478347-1115281.html

上一篇:Windows大型软件安装错误的一般解决方法
下一篇:VASP VDW修正方法的选择
收藏 IP: 218.98.26.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-7-20 04:23

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部