程序化更新所有pip

为了自己安装的pip组件,写了个一揽子更新全部pip,自己写了个(代码中的路径自行修改),感觉用着还可以,代码如下:

# -*- coding: utf-8 -*-

import os

tempfile1 = 'd:/a.txt'

tempfile2 = 'D:/pipupdata.bat'

python_path = '"D:/Program Files/python/python.exe"'

pip_path = '"D:/Program Files/python/Scripts/pip.exe"'

os.system("%s list >%s" % (pip_path, tempfile1))

data = []

with open(tempfile1,"r") as f:

line_len=len(f.readlines());

f.seek(0,0)

for line in f.readlines()[2:]: #前两行为头及分割线,无需读入数组

line = line.strip("\n")

line = line.split()

data.append(line[0])

f.close()

with open(tempfile2,"w") as f:

data_len=len(data)

f.write("%s -m pip install --upgrade pip \n" % (python_path))

f.write("@rem %s install pip-review \n" % (pip_path))

f.write("@rem pip-review --auto \n")

f.write("@rem %s list >%s \n" % (pip_path, tempfile1))

f.write("@rem %s freeze >%s \n" % (pip_path, tempfile1))

for i in range(2,data_len):

f.write("%s install -U %s \n" % (pip_path, data[i]))

f.close()

os.remove(tempfile1)

os.system(tempfile2)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值