鱼C论坛

 找回密码
 立即注册
查看: 2609|回复: 0

[技术交流] 【python】使用代码批量更新Python模块

[复制链接]
发表于 2020-10-25 20:51:16 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
升级包其实很简单,就是pip install -U *   
  • 就是你包的名称。不过当包很多的时候就很麻烦了。

    步骤很简单。
    进入cmd (别告诉我你不会)输入 pip list --outdate 命令,查看哪些包需要升级。
    然后复制全部结果,等下会用到。
    打开你的编辑器,什么都行,我用的是jupyter notebook. 输入下面的代码。
    【*】你只需要修改的地方就是 变量info的内容,删除之前的换成你电脑上面需要升级的就行了,很简单。
    【*】升级的速度取决你电脑的网速,模块的数量,以及更新源的地址,我已经提前将源全部改成清华的了,所以更新很快(百度下有很多方法,我这里就不赘述了。)
    【*】希望对你有帮助。
    1. import os


    2. info = """
    3. attrs             19.3.0     20.2.0       wheel
    4. beautifulsoup4    4.9.1      4.9.3        wheel
    5. bleach            3.1.5      3.2.1        wheel
    6. cffi              1.14.1     1.14.3       wheel
    7. colorama          0.4.3      0.4.4        wheel
    8. Eel               0.13.2     0.14.0       sdist
    9. Faker             4.1.1      4.14.0       wheel
    10. gevent            20.6.2     20.9.0       wheel
    11. greenlet          0.4.16     0.4.17       wheel
    12. iniconfig         1.0.1      1.1.1        wheel
    13. ipykernel         5.3.2      5.3.4        wheel
    14. ipython           7.16.1     7.18.1       wheel
    15. isort             4.3.21     5.6.4        wheel
    16. jedi              0.17.1     0.17.2       wheel
    17. jupyter-client    6.1.6      6.1.7        wheel
    18. jupyter-console   6.1.0      6.2.0        wheel
    19. jupyter-kite      1.1.0      1.2.0        sdist
    20. lazy-object-proxy 1.4.3      1.5.1        wheel
    21. lxml              4.5.2      4.6.1        wheel
    22. matplotlib        3.3.0      3.3.2        wheel
    23. more-itertools    8.4.0      8.5.0        wheel
    24. nbconvert         5.6.1      6.0.7        wheel
    25. nbformat          5.0.7      5.0.8        wheel
    26. notebook          6.0.3      6.1.4        wheel
    27. numpy             1.19.0     1.19.2       wheel
    28. openpyxl          3.0.4      3.0.5        wheel
    29. pandas            1.1.0      1.1.3        wheel
    30. pandocfilters     1.4.2      1.4.3        sdist
    31. parso             0.7.0      0.8.0        wheel
    32. Pillow            7.2.0      8.0.1        wheel
    33. pip               20.2.3     20.2.4       wheel
    34. prompt-toolkit    3.0.5      3.0.8        wheel
    35. Pygments          2.6.1      2.7.2        wheel
    36. PyInstaller       3.6        4.0          sdist
    37. pylint            2.5.3      2.6.0        wheel
    38. PyQt5             5.15.0     5.15.1       wheel
    39. PyQt5-sip         12.8.0     12.8.1       wheel
    40. pyqt5-tools       5.15.0.1.7 5.15.1.1.7.5 wheel
    41. PyQtChart         5.15.0     5.15.1       wheel
    42. PyQtWebEngine     5.15.0     5.15.1       wheel
    43. pyrsistent        0.16.0     0.17.3       sdist
    44. PySide2           5.15.0     5.15.1       wheel
    45. pytest            6.0.1      6.1.1        wheel
    46. pyzmq             19.0.1     19.0.2       wheel
    47. qtconsole         4.7.5      4.7.7        wheel
    48. setuptools        41.2.0     50.3.2       wheel
    49. shiboken2         5.15.0     5.15.1       wheel
    50. sip               5.3.0      5.4.0        wheel
    51. terminado         0.8.3      0.9.1        wheel
    52. tqdm              4.48.0     4.50.2       wheel
    53. traitlets         4.3.3      5.0.5        wheel
    54. urllib3           1.25.9     1.25.11      wheel
    55. XlsxWriter        1.2.9      1.3.7        wheel
    56. zope.event        4.4        4.5.0        wheel
    57. zope.interface    5.1.0      5.1.2        wheel
    58. """

    59. item = info.replace('wheel', '').replace('sdist', '').split()
    60. for i in item:
    61.     if i.isalnum():
    62.         print('正在升级:{}'.format(i))
    63.         os.system('pip install -U {}'.format(i))
    复制代码

    附上3张图。
  • cmd_dos.png
    update.png
    3.png
    想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

    GMT+8, 2024-5-13 09:08

    Powered by Discuz! X3.4

    © 2001-2023 Discuz! Team.

    快速回复 返回顶部 返回列表