精易论坛

标题: Python写的Python 模块安装小工具 [打印本页]

作者: 姚海平    时间: 2020-2-2 20:50
标题: Python写的Python 模块安装小工具
本帖最后由 姚海平 于 2020-2-2 20:56 编辑

国内环境安装Python模块要输入豆瓣或清华的地址,每次输入比较麻烦,便用Python写了个小工具,只要输入模块名,点击就可以安装了,DOS窗口中会显示安装进度。
下面是Python3代码:
  1. import os
  2. import subprocess
  3. from tkinter import *

  4. root = Tk()
  5. root.title('Python安装模块')
  6. root.geometry("+400+300")

  7. #设置pip路径
  8. pip_path = r'D:\IDE\Python3\Scripts\pip.exe'

  9. #设置模块界面
  10. Label(root, text='模块名:').pack(side=LEFT)
  11. text = Text(root, width=14, height=1)
  12. text.focus()
  13. text.pack(side=LEFT)

  14. #安装模块
  15. def call_button():
  16.     #获取模块名
  17.     m_name = text.get(1.0, END)
  18.     #设置pip安装命令行
  19.     pip_install_cmd = r'cmd.exe /c ' + pip_path + r' install -i https://pypi.doubanio.com/simple/ ' + m_name
  20.     print(pip_install_cmd)
  21.     #os.popen(pip_install_cmd)
  22.     subprocess.Popen(pip_install_cmd, shell=False)

  23. Button(root, text='安装模块', command=call_button).pack()

  24. root.mainloop()
复制代码



作者: badlwolf    时间: 2020-12-30 17:19
哈哈哈,这个可以,国内环境确实很糟心




欢迎光临 精易论坛 (https://125.confly.eu.org/) Powered by Discuz! X3.4