话说你们用Python打代码用的做多的是什么代码
打住!我猜就是
pip install xxx
是不是?是不是?
所以呢,为了让安装库更加的方便,我花午休45分钟写了这玩意:
前面全是Beta,当前的V1.2加上了除了安装、卸载以外其他全部功能(上面截图中的窗口标题有误,现已修改)。
还是话不多说,就上代码给大家细品吧
import os import tkinter as tk import tkinter.ttk as ttk from tkinter.filedialog import askdirectory import webbrowser def init(): global py_path,pip_path try: print('正在读取') py_path_f=open("./py_path.cfg",'r',encoding='utf-8') py_path=py_path_f.read() print(py_path) py_path_f.close() pip_path=py_path+"/scripts/pip.exe" print('读取完成') if py_path=='使用环境变量': print('使用环境变量') pip_path='pip' except Exception as e: print('读取设置失败:'+str(e)) py_path=askdirectory(title='请选择Python安装路径') py_path_f=open("./py_path.cfg",'w',encoding='utf-8') py_path_f.write(py_path) py_path_f.close() pip_path=py_path+"/scripts/pip.exe" def locate_pip(): os.system("where pip") os.system("where pip3") print('==================================================') def install(name): os.system(pip_path+" install "+name+' -i https://pypi.douban.com/simple') print('==================================================') def uninstall(): os.system(pip_path+" uninstall "+name) print('==================================================') def about(): os.system(py_path+"/python.exe -m pip install --upgrade pip -i https://pypi.douban.com/simple") print('==================================================') def list_pkg(): os.system(pip_path+" list") print('==================================================') win=tk.Tk() win.title('Easy Pypi V1.2') win.geometry('300x370') win.resizable(0,0) init() print('==================================================') name_enter=ttk.Entry(win) name_enter.pack(fill=tk.X) print('执行: '+pip_path+' install '+'(库名)'+' -i https://pypi.douban.com/simple') ttk.Button(win,text='安装',command=lambda:install(name_enter.get())).pack(fill=tk.X) ttk.Button(win,text='卸载',command=uninstall).pack(fill=tk.X) ttk.Button(win,text='列出所有已经安装的库',command=list_pkg).pack(fill=tk.X) ttk.Button(win,text='更新PIP',command=about).pack(fill=tk.X) ttk.Button(win,text='关于PIP',command=lambda:os.system(pip_path+" --version")).pack(fill=tk.X) ttk.Button(win,text='查看环境变量中有关PIP路径的配置',command=locate_pip).pack(fill=tk.X) tk.Label(win,text='介绍',bg='lightgrey').pack(fill=tk.X) tk.Label(win,text='这个程序可以方便地从Pypi安装第三方库').pack(fill=tk.X) tk.Label(win,text='默认使用豆瓣镜像源以提升速度').pack(fill=tk.X) tk.Label(win,text='使用步骤',bg='lightgrey').pack(fill=tk.X) tk.Label(win,text='1.在窗口顶部的输入框内输入库名').pack(fill=tk.X) tk.Label(win,text='2.点击点击相关的功能按钮').pack(fill=tk.X) tk.Label(win,text='3.等待操作完毕(不要关闭弹出的命令提示符)').pack(fill=tk.X) tk.Button(win,text='2022 By 人工智障',bg='lightgrey',bd=0,command=lambda:webbrowser.open("https://www.cnblogs.com/totowang")).pack(fill=tk.X) win.mainloop()