吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 5782|回复: 51
收起左侧

[原创工具] python库安装工具

[复制链接]
爱月亮的胡萝卜 发表于 2023-4-15 21:59
简化python库的安装过程,制作专属安装工具。

特点:定位一次python库的安装目录,下次安装库不再需要定位。只用输入库名称。




python库的安装方法:
1.定位到python安装目录的Scripts。例如:C:\Users\***\AppData\Local\Programs\Python\Python38\Scripts
2.将路径输入到该软件的目录路径框中
3.输入要安装的库名称。例如:要安装Requests,直接输入Requests即可。
4.点击运行,包存路径请点击保存设置。
[Python] 纯文本查看 复制代码
import os
import configparser
import tkinter as tk
from tkinter import messagebox

class App(tk.Tk):
    def __init__(self):
        super().__init__()
        self.title("库安装器")
        self.geometry("500x300")
        self.config_file = "config.ini"
        self.folder_path = tk.StringVar()
        self.lib_name = tk.StringVar()
        self.read_config()
        self.create_widgets()

    def read_config(self):
        config = configparser.ConfigParser()
        if os.path.exists(self.config_file):
            config.read(self.config_file)
            if "设置" in config:
                self.folder_path.set(config["设置"].get("目录路径", ""))
        else:
            self.create_config()
    
    def create_config(self):
        config = configparser.ConfigParser()
        config["设置"] = {}
        config["设置"]["目录路径"] = ""
        with open(self.config_file, "w") as f:
            config.write(f)

    def save_config(self):
        config = configparser.ConfigParser()
        config["设置"] = {}
        config["设置"]["目录路径"] = self.folder_path.get()
        with open(self.config_file, "w") as f:
            config.write(f)

    def create_widgets(self):
        # Label and Entry for folder path
        tk.Label(self, text="目录路径:").grid(row=0, column=0, padx=10, pady=10)
        tk.Entry(self, textvariable=self.folder_path).grid(row=0, column=1, padx=10, pady=10)

        # Label and Entry for library name
        tk.Label(self, text="库名称:").grid(row=1, column=0, padx=10, pady=10)
        tk.Entry(self, textvariable=self.lib_name).grid(row=1, column=1, padx=10, pady=10)

        # Buttons for running and quitting
        tk.Button(self, text="运行", command=self.run).grid(row=2, column=0, padx=10, pady=10)
        tk.Button(self, text="退出", command=self.quit).grid(row=2, column=1, padx=10, pady=10)

        # Button for saving settings
        tk.Button(self, text="保存设置", command=self.save_config).grid(row=3, column=0, padx=10, pady=10)

    def run(self):
        folder_path = self.folder_path.get()
        lib_name = self.lib_name.get()
        if not os.path.exists(folder_path):
            messagebox.showerror("错误", "目录路径不存在!")
        else:
            os.chdir(folder_path)
            result = os.system(f"pip install -i https://pypi.tuna.tsinghua.edu.cn/simple {lib_name}")
            if result == 0:
                messagebox.showinfo("成功", "库安装成功!")
            else:
                messagebox.showerror("错误", f"库安装失败!错误代码: {result}")
    def uninstall(self):
        folder_path = self.folder_path.get()
        lib_name = self.lib_name.get()
        if not os.path.exists(folder_path):
            messagebox.showerror("Error", "Folder path does not exist!")
        else:
            os.chdir(folder_path)
            result = os.system(f"pip uninstall -y {lib_name}")
            if result == 0:
                messagebox.showinfo("Success", "Library uninstallation successful!")
            else:
                messagebox.showerror("Error", f"Library uninstallation failed! Error code: {result}")
app = App()
app.mainloop()

软件截图:



源码和程序下载地址:链接:https://pan.baidu.com/s/1b3cE4WuE1q561yTEIq9sfw
提取码:52pj

免费评分

参与人数 4吾爱币 +10 热心值 +4 收起 理由
tangerine122 + 1 + 1 谢谢@Thanks!
Fwing + 1 + 1 我很赞同!
★天若有情★ + 1 + 1 热心回复!
风之暇想 + 7 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

头像被屏蔽
zb848 发表于 2023-4-21 17:14
提示: 作者被禁止或删除 内容自动屏蔽
zixudaoxian 发表于 2023-4-17 09:34
zhuangbo 发表于 2023-4-17 07:18
zrqnysz 发表于 2023-4-17 07:24
方便了!超赞
52012978 发表于 2023-4-17 08:08
感谢大佬 正在入门学PYTHON
5151diy 发表于 2023-4-17 08:17
感谢,提供方法,如某编辑器python  调用库文件是这个路径C:%homepath%\AppData\Local
halloseven 发表于 2023-4-17 09:28
感谢楼主分享
powerpc2008 发表于 2023-4-17 09:35
感谢楼主分享
dancershou 发表于 2023-4-17 10:14
感谢发布原创作品,吾爱破解论坛因你更精彩!
ZforCoding329 发表于 2023-4-17 10:38
这个和pip install有什么区别呢
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 提醒:禁止复制他人回复等『恶意灌水』行为,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-16 16:49

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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