標籤:

為什麼PIP不提供更新所有包的方法?

為什麼PIP不提供更新所有包的方法?雖然可以崎嶇的更新所有的包,但是為什麼不提供一鍵的方法呢?類似於apt 的 upgrade呢


pip freeze --local | grep -v ^-e | cut -d = -f 1 | xargs pip install -U


import pip
from subprocess import call
for package in pip.get_installed_distributions():
call(pip install --upgrade + package.project_name)

自己寫了一個更新site-packages文件夾下所有包的代碼,上面的代碼輸出結果如下

Requirement already up-to-date: zope.interface in d:pythonlibsite-packages
Collecting setuptools (from zope.interface)
Downloading setuptools-36.2.5-py2.py3-none-any.whl (477kB)
100% |████████████████████████████████| 481kB 105kB/s
Installing collected packages: setuptools
Found existing installation: setuptools 36.2.4
Uninstalling setuptools-36.2.4:
Successfully uninstalled setuptools-36.2.4
Successfully installed setuptools-36.2.5
Requirement already up-to-date: wrapt in d:pythonlibsite-packages
Requirement already up-to-date: webencodings in d:pythonlibsite-packages
Requirement already up-to-date: w3lib in d:pythonlibsite-packages
Requirement already up-to-date: six&>=1.4.1 in d:pythonlibsite-packages (from w3lib)
Requirement already up-to-date: urllib3 in d:pythonlibsite-packages
Requirement already up-to-date: Twisted in d:pythonlibsite-packages
Requirement already up-to-date: hyperlink&>=17.1.1 in d:pythonlibsite-packages (from Twisted)
Requirement already up-to-date: incremental&>=16.10.1 in d:pythonlibsite-packages (from Twisted)
Requirement already up-to-date: zope.interface&>=4.0.2 in d:pythonlibsite-packages (from Twisted)
Requirement already up-to-date: constantly&>=15.1 in d:pythonlibsite-packages (from Twisted)
Requirement already up-to-date: Automat&>=0.3.0 in d:pythonlibsite-packages (from Twisted)
Requirement already up-to-date: setuptools in d:pythonlibsite-packages (from zope.interface&>=4.0.2-&>Twisted)
Requirement already up-to-date: attrs in d:pythonlibsite-packages (from Automat&>=0.3.0-&>Twisted)
Requirement already up-to-date: six in d:pythonlibsite-packages (from Automat&>=0.3.0-&>Twisted)
Requirement already up-to-date: six in d:pythonlibsite-packages
Requirement already up-to-date: si in d:pythonlibsite-packages
Requirement already up-to-date: setuptools in d:pythonlibsite-packages
Requirement already up-to-date: setupfiles in d:pythonlibsite-packages
Requirement already up-to-date: service-identity in d:pythonlibsite-packages
Requirement already up-to-date: pyasn1-modules in d:pythonlibsite-packages (from service-identity)
Requirement already up-to-date: pyopenssl&>=0.12 in d:pythonlibsite-packages (from service-identity)
Requirement already up-to-date: pyasn1 in d:pythonlibsite-packages (from service-identity)
Requirement already up-to-date: attrs in d:pythonlibsite-packages (from service-identity)
Requirement already up-to-date: six&>=1.5.2 in d:pythonlibsite-packages (from pyopenssl&>=0.12-&>service-identity)
Requirement already up-to-date: cryptography&>=1.9 in d:pythonlibsite-packages (from pyopenssl&>=0.12-&>service-identity)
Requirement already up-to-date: idna&>=2.1 in d:pythonlibsite-packages (from cryptography&>=1.9-&>pyopenssl&>=0.12-&>service-identity)
Requirement already up-to-date: asn1crypto&>=0.21.0 in d:pythonlibsite-packages (from cryptography&>=1.9-&>pyopenssl&>=0.12-&>service-identity)
Requirement already up-to-date: cffi&>=1.7 in d:pythonlibsite-packages (from cryptography&>=1.9-&>pyopenssl&>=0.12-&>service-identity)
Requirement already up-to-date: pycparser in d:pythonlibsite-packages (from cffi&>=1.7-&>cryptography&>=1.9-&>pyopenssl&>=0.12-&>service-identity)
Requirement already up-to-date: Scrapy in d:pythonlibsite-packages
Requirement already up-to-date: parsel&>=1.1 in d:pythonlibsite-packages (from Scrapy)
Requirement already up-to-date: w3lib&>=1.17.0 in d:pythonlibsite-packages (from Scrapy)
Requirement already up-to-date: cssselect&>=0.9 in d:pythonlibsite-packages (from Scrapy)
Requirement already up-to-date: pyOpenSSL in d:pythonlibsite-packages (from Scrapy)
Requirement already up-to-date: service-identity in d:pythonlibsite-packages (from Scrapy)
Requirement already up-to-date: queuelib in d:pythonlibsite-packages (from Scrapy)
Requirement already up-to-date: lxml in d:pythonlibsite-packages (from Scrapy)
Requirement already up-to-date: PyDispatcher&>=2.0.5 in d:pythonlibsite-packages (from Scrapy)
Requirement already up-to-date: Twisted&>=13.1.0 in d:pythonlibsite-packages (from Scrapy)
Requirement already up-to-date: six&>=1.5.2 in d:pythonlibsite-packages (from Scrapy)
Requirement already up-to-date: cryptography&>=1.9 in d:pythonlibsite-packages (from pyOpenSSL-&>Scrapy)
Requirement already up-to-date: pyasn1-modules in d:pythonlibsite-packages (from service-identity-&>Scrapy)
Requirement already up-to-date: attrs in d:pythonlibsite-packages (from service-identity-&>Scrapy)
Requirement already up-to-date: pyasn1 in d:pythonlibsite-packages (from service-identity-&>Scrapy)
Requirement already up-to-date: zope.interface&>=4.0.2 in d:pythonlibsite-packages (from Twisted&>=13.1.0-&>Scrapy)
Requirement already up-to-date: hyperlink&>=17.1.1 in d:pythonlibsite-packages (from Twisted&>=13.1.0-&>Scrapy)
Requirement already up-to-date: incremental&>=16.10.1 in d:pythonlibsite-packages (from Twisted&>=13.1.0-&>Scrapy)
Requirement already up-to-date: Automat&>=0.3.0 in d:pythonlibsite-packages (from Twisted&>=13.1.0-&>Scrapy)
Requirement already up-to-date: constantly&>=15.1 in d:pythonlibsite-packages (from Twisted&>=13.1.0-&>Scrapy)
Requirement already up-to-date: cffi&>=1.7 in d:pythonlibsite-packages (from cryptography&>=1.9-&>pyOpenSSL-&>Scrapy)
Requirement already up-to-date: idna&>=2.1 in d:pythonlibsite-packages (from cryptography&>=1.9-&>pyOpenSSL-&>Scrapy)
Requirement already up-to-date: asn1crypto&>=0.21.0 in d:pythonlibsite-packages (from cryptography&>=1.9-&>pyOpenSSL-&>Scrapy)
Requirement already up-to-date: setuptools in d:pythonlibsite-packages (from zope.interface&>=4.0.2-&>Twisted&>=13.1.0-&>Scrapy)
Requirement already up-to-date: pycparser in d:pythonlibsite-packages (from cffi&>=1.7-&>cryptography&>=1.9-&>pyOpenSSL-&>Scrapy)
Requirement already up-to-date: requests in d:pythonlibsite-packages
Requirement already up-to-date: urllib3&<1.23,&>=1.21.1 in d:pythonlibsite-packages (from requests)
Requirement already up-to-date: certifi&>=2017.4.17 in d:pythonlibsite-packages (from requests)
Requirement already up-to-date: idna&<2.6,&>=2.5 in d:pythonlibsite-packages (from requests)
Requirement already up-to-date: chardet&<3.1.0,&>=3.0.2 in d:pythonlibsite-packages (from requests)
Requirement already up-to-date: request in d:pythonlibsite-packages
Requirement already up-to-date: get in d:pythonlibsite-packages (from request)
Requirement already up-to-date: post in d:pythonlibsite-packages (from request)
Requirement already up-to-date: setupfiles in d:pythonlibsite-packages (from request)
Requirement already up-to-date: query_string in d:pythonlibsite-packages (from get-&>request)
Requirement already up-to-date: public in d:pythonlibsite-packages (from query_string-&>get-&>request)
Requirement already up-to-date: queuelib in d:pythonlibsite-packages
Requirement already up-to-date: query-string in d:pythonlibsite-packages
Requirement already up-to-date: public in d:pythonlibsite-packages (from query-string)
Requirement already up-to-date: setupfiles in d:pythonlibsite-packages (from query-string)
Requirement already up-to-date: pyt in d:pythonlibsite-packages
Requirement already up-to-date: PyQRCode in d:pythonlibsite-packages
Requirement already up-to-date: pypng in d:pythonlibsite-packages
Requirement already up-to-date: pypiwin32 in d:pythonlibsite-packages
Requirement already up-to-date: pyOpenSSL in d:pythonlibsite-packages
Requirement already up-to-date: cryptography&>=1.9 in d:pythonlibsite-packages (from pyOpenSSL)
Requirement already up-to-date: six&>=1.5.2 in d:pythonlibsite-packages (from pyOpenSSL)
Requirement already up-to-date: asn1crypto&>=0.21.0 in d:pythonlibsite-packages (from cryptography&>=1.9-&>pyOpenSSL)
Requirement already up-to-date: cffi&>=1.7 in d:pythonlibsite-packages (from cryptography&>=1.9-&>pyOpenSSL)
Requirement already up-to-date: idna&>=2.1 in d:pythonlibsite-packages (from cryptography&>=1.9-&>pyOpenSSL)
Requirement already up-to-date: pycparser in d:pythonlibsite-packages (from cffi&>=1.7-&>cryptography&>=1.9-&>pyOpenSSL)
Requirement already up-to-date: pylint in d:pythonlibsite-packages
Requirement already up-to-date: mccabe in d:pythonlibsite-packages (from pylint)
Requirement already up-to-date: six in d:pythonlibsite-packages (from pylint)
Requirement already up-to-date: isort&>=4.2.5 in d:pythonlibsite-packages (from pylint)
Requirement already up-to-date: astroid&>=1.5.1 in d:pythonlibsite-packages (from pylint)
Requirement already up-to-date: colorama; sys_platform == "win32" in d:pythonlibsite-packages (from pylint)
Requirement already up-to-date: wrapt in d:pythonlibsite-packages (from astroid&>=1.5.1-&>pylint)
Requirement already up-to-date: lazy-object-proxy in d:pythonlibsite-packages (from astroid&>=1.5.1-&>pylint)
Requirement already up-to-date: PyDispatcher in d:pythonlibsite-packages
Requirement already up-to-date: pycparser in d:pythonlibsite-packages
Requirement already up-to-date: pycodestyle in d:pythonlibsite-packages
Requirement already up-to-date: pyasn1 in d:pythonlibsite-packages
Requirement already up-to-date: pyasn1-modules in d:pythonlibsite-packages
Requirement already up-to-date: pyasn1&>=0.1.8 in d:pythonlibsite-packages (from pyasn1-modules)
Requirement already up-to-date: public in d:pythonlibsite-packages
Requirement already up-to-date: setupfiles in d:pythonlibsite-packages (from public)
Requirement already up-to-date: post in d:pythonlibsite-packages
Requirement already up-to-date: setupfiles in d:pythonlibsite-packages (from post)
Requirement already up-to-date: pip in d:pythonlibsite-packages
Requirement already up-to-date: parsel in d:pythonlibsite-packages
Requirement already up-to-date: six&>=1.5.2 in d:pythonlibsite-packages (from parsel)
Requirement already up-to-date: cssselect&>=0.9 in d:pythonlibsite-packages (from parsel)
Requirement already up-to-date: w3lib&>=1.8.0 in d:pythonlibsite-packages (from parsel)
Requirement already up-to-date: lxml&>=2.3 in d:pythonlibsite-packages (from parsel)
Requirement already up-to-date: parse in d:pythonlibsite-packages
Requirement already up-to-date: numpy in d:pythonlibsite-packages
Requirement already up-to-date: mccabe in d:pythonlibsite-packages
Requirement already up-to-date: lxml in d:pythonlibsite-packages
Requirement already up-to-date: lazy-object-proxy in d:pythonlibsite-packages
Requirement already up-to-date: itchat in d:pythonlibsite-packages
Requirement already up-to-date: pypng in d:pythonlibsite-packages (from itchat)
Requirement already up-to-date: requests in d:pythonlibsite-packages (from itchat)
Requirement already up-to-date: pyqrcode in d:pythonlibsite-packages (from itchat)
Requirement already up-to-date: urllib3&<1.23,&>=1.21.1 in d:pythonlibsite-packages (from requests-&>itchat)
Requirement already up-to-date: chardet&<3.1.0,&>=3.0.2 in d:pythonlibsite-packages (from requests-&>itchat)
Requirement already up-to-date: certifi&>=2017.4.17 in d:pythonlibsite-packages (from requests-&>itchat)
Requirement already up-to-date: idna&<2.6,&>=2.5 in d:pythonlibsite-packages (from requests-&>itchat)
Requirement already up-to-date: isort in d:pythonlibsite-packages
Requirement already up-to-date: incremental in d:pythonlibsite-packages
Requirement already up-to-date: idna in d:pythonlibsite-packages
Requirement already up-to-date: hyperlink in d:pythonlibsite-packages
Requirement already up-to-date: html5lib in d:pythonlibsite-packages
Requirement already up-to-date: webencodings in d:pythonlibsite-packages (from html5lib)
Requirement already up-to-date: setuptools&>=18.5 in d:pythonlibsite-packages (from html5lib)
Requirement already up-to-date: six in d:pythonlibsite-packages (from html5lib)
Requirement already up-to-date: get in d:pythonlibsite-packages
Requirement already up-to-date: query_string in d:pythonlibsite-packages (from get)
Requirement already up-to-date: setupfiles in d:pythonlibsite-packages (from get)
Requirement already up-to-date: public in d:pythonlibsite-packages (from query_string-&>get)
Requirement already up-to-date: cssselect in d:pythonlibsite-packages
Requirement already up-to-date: cryptography in d:pythonlibsite-packages
Requirement already up-to-date: six&>=1.4.1 in d:pythonlibsite-packages (from cryptography)
Requirement already up-to-date: cffi&>=1.7 in d:pythonlibsite-packages (from cryptography)
Requirement already up-to-date: idna&>=2.1 in d:pythonlibsite-packages (from cryptography)
Requirement already up-to-date: asn1crypto&>=0.21.0 in d:pythonlibsite-packages (from cryptography)
Requirement already up-to-date: pycparser in d:pythonlibsite-packages (from cffi&>=1.7-&>cryptography)
Requirement already up-to-date: constantly in d:pythonlibsite-packages
Requirement already up-to-date: colorama in d:pythonlibsite-packages
Requirement already up-to-date: chardet in d:pythonlibsite-packages
Requirement already up-to-date: cffi in d:pythonlibsite-packages
Requirement already up-to-date: pycparser in d:pythonlibsite-packages (from cffi)
Requirement already up-to-date: certifi in d:pythonlibsite-packages
Requirement already up-to-date: bs4 in d:pythonlibsite-packages
Requirement already up-to-date: beautifulsoup4 in d:pythonlibsite-packages (from bs4)
Requirement already up-to-date: beautifulsoup4 in d:pythonlibsite-packages
Requirement already up-to-date: autopep8 in d:pythonlibsite-packages
Requirement already up-to-date: pycodestyle&>=2.3 in d:pythonlibsite-packages (from autopep8)
Requirement already up-to-date: Automat in d:pythonlibsite-packages
Requirement already up-to-date: six in d:pythonlibsite-packages (from Automat)
Requirement already up-to-date: attrs in d:pythonlibsite-packages (from Automat)
Requirement already up-to-date: attrs in d:pythonlibsite-packages
Requirement already up-to-date: attr in d:pythonlibsite-packages
Requirement already up-to-date: astroid in d:pythonlibsite-packages
Requirement already up-to-date: six in d:pythonlibsite-packages (from astroid)
Requirement already up-to-date: wrapt in d:pythonlibsite-packages (from astroid)
Requirement already up-to-date: lazy-object-proxy in d:pythonlibsite-packages (from astroid)
Requirement already up-to-date: asn1crypto in d:pythonlibsite-packages

可以看到,只有第二個有更新,其他的都是最新的。我差不多每天運行一次這個程序,有時候會遇到某個包更新了,然後又被其他包退回了,估計是由於其他的安裝包在寫的時候依賴於特定版本的某個包。上面有很多&>=, &< 這些符號就是限定版本的


自己動手,豐衣足食~

#!/user/bin python
# -*- coding:utf-8 -*-

@Author: GETF
@Email: GETF_own@163.com
@DateTime: 2018-05-07 21:45:03
@Description: 一鍵更新庫

import os

result = os.popen(pip list) #執行系統命令,返回值為result
res = result.read()
data = res.split()
demo = []
length = len(data)
i = 4
while(i &< length): demo.append(data[i]) i = i+2 for package in demo: os.system(pip install --upgrade +package) print("all update")


import subprocess as sbp
import pip
pkgs = eval(str(sbp.run("pip3 list -o --format=json", shell=True,
stdout=sbp.PIPE).stdout, encoding=utf-8))
for pkg in pkgs:
sbp.run("pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade " + pkg[name], shell=True)

保存成 xx.py

然後運行 Python3 xx.py

ENV Python 3.5+ pip 10.0+ (低版本改改

其中 https://pypi.tuna.tsinghua.edu.cn/simple 可以用默認的,或換成其他源


類似於apt 的 upgrade呢??

正是因為沒有這種方法,所為很慶幸。

不然,你就要問,「什麼更新一下python模塊,軟體都不能用了?」

難道不知道 「依賴」這個詞嗎?


可以更新哈,你搜搜pip install uprade all 。


推薦閱讀:

從零開始的python世界的闖蕩之視頻學習篇 第一話 Linux命令基礎
Python-Fun Merchants Guide To The Galaxy
代碼這樣寫不止於優雅(Python版)
[轉載]python 的日誌logging模塊學習

TAG:Python |