|
本帖最后由 姚海平 于 2020-2-2 20:56 编辑
国内环境安装Python模块要输入豆瓣或清华的地址,每次输入比较麻烦,便用Python写了个小工具,只要输入模块名,点击就可以安装了,DOS窗口中会显示安装进度。
下面是Python3代码:
- import os
- import subprocess
- from tkinter import *
- root = Tk()
- root.title('Python安装模块')
- root.geometry("+400+300")
- #设置pip路径
- pip_path = r'D:\IDE\Python3\Scripts\pip.exe'
- #设置模块界面
- Label(root, text='模块名:').pack(side=LEFT)
- text = Text(root, width=14, height=1)
- text.focus()
- text.pack(side=LEFT)
- #安装模块
- def call_button():
- #获取模块名
- m_name = text.get(1.0, END)
- #设置pip安装命令行
- pip_install_cmd = r'cmd.exe /c ' + pip_path + r' install -i https://pypi.doubanio.com/simple/ ' + m_name
- print(pip_install_cmd)
- #os.popen(pip_install_cmd)
- subprocess.Popen(pip_install_cmd, shell=False)
- Button(root, text='安装模块', command=call_button).pack()
- root.mainloop()
复制代码
|
|