吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 5815|回复: 45
收起左侧

[Python 原创] 用deepseek- r1 学习 Python的第一天

[复制链接]
dapkouatao1 发表于 2025-2-13 21:07
首先呢思路是怎么来的呢,今天是自学python的第一天我想着做一个计算机,我发现他的命令跟代码跟e语言很像,我就尝试着整理了一下
但是我的计算器是做出来了,问题是怎么打包, 我不会啊,然后我就突发奇想运用deepseek去写了一个代码。

第一

第一

实话说这运行的时间是我这几次去研究deepseek最慢的情况了。

第二

第二

代码直接无脑复制粘贴进去了以后
开始报错
发现问题就因为 打包插件没下载

3

3

又开始测试 继续让他跑 还是出现了问题我又跑到各种网站去找攻略
最后没办法又交给了deepseek

4

4

是真的牛逼 直接给了最解优
代码看不懂 难道抄咱们还不会吗 直接安排上(就找这行代码找了半天)

5

5

找到并修改过后我继续让它跑起来 但还是问题不断

6

6

咋个办 继续问把 谁让咱是一个废物呢,

7

7

实话说修改的这个问题我看懂了,但是

8

8

这个还是看不懂  我只是不懂什么叫叫类初始之后
我就直接瞎放了,但是成功了跑了起来   
我的计算器也成功的一键生成了exe的文件
然后我写的

9

9

可以用很且很好用,但是又出现问题了
我可以打包其他的py文件。但是它自己这个文件却打包不了

import sys
import io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
import tkinter as tk
from tkinter import filedialog, ttk
import subprocess
import os
from threading import Thread
import queue


class PyToExeConverter:
    def __init__(self, master):
        self.master = master
        master.title("PythonEXE工具")

        # 初始化界面布局
        self.create_widgets()

        # 日志队列和运行状态
        self.log_queue = queue.Queue()
        self.running = False

    def create_widgets(self):
        """创建界面组件"""
        # 文件列表
        self.listbox = tk.Listbox(self.master, width=80, height=10)
        self.listbox.grid(row=0, column=0, columnspan=3, padx=10, pady=5)

        # 按钮框架
        btn_frame = tk.Frame(self.master)
        btn_frame.grid(row=1, column=0, columnspan=3, pady=5)

        tk.Button(btn_frame, text="添加文件", command=self.add_files).pack(side=tk.LEFT, padx=5)
        tk.Button(btn_frame, text="添加目录", command=self.add_directory).pack(side=tk.LEFT, padx=5)
        tk.Button(btn_frame, text="清空列表", command=self.clear_list).pack(side=tk.LEFT, padx=5)

        # 输出目录
        output_frame = tk.Frame(self.master)
        output_frame.grid(row=2, column=0, columnspan=3, pady=5)

        tk.Label(output_frame, text="输出目录:").pack(side=tk.LEFT)
        self.output_path = tk.StringVar()
        tk.Entry(output_frame, textvariable=self.output_path, width=50).pack(side=tk.LEFT, padx=5)
        tk.Button(output_frame, text="浏览", command=self.choose_output).pack(side=tk.LEFT)

        # 打包选项
        option_frame = tk.Frame(self.master)
        option_frame.grid(row=3, column=0, columnspan=3, pady=5)

        self.onefile = tk.BooleanVar()
        tk.Checkbutton(option_frame, text="单文件", variable=self.onefile).pack(side=tk.LEFT, padx=5)

        self.noconsole = tk.BooleanVar()
        tk.Checkbutton(option_frame, text="无控制台", variable=self.noconsole).pack(side=tk.LEFT, padx=5)

        tk.Label(option_frame, text="图标:").pack(side=tk.LEFT)
        self.icon_path = tk.StringVar()
        tk.Entry(option_frame, textvariable=self.icon_path, width=30).pack(side=tk.LEFT, padx=5)
        tk.Button(option_frame, text="浏览", command=self.choose_icon).pack(side=tk.LEFT)

        # 开始按钮
        self.start_btn = tk.Button(self.master, text="开始打包", command=self.start_conversion)
        self.start_btn.grid(row=4, column=0, columnspan=3, pady=10)

        # 日志输出
        self.log_text = tk.Text(self.master, width=80, height=15)
        self.log_text.grid(row=5, column=0, columnspan=3, padx=10, pady=5)

        # 状态栏
        self.status = tk.StringVar()
        tk.Label(self.master, textvariable=self.status, relief=tk.SUNKEN, anchor=tk.W).grid(
            row=6, column=0, columnspan=3, sticky=tk.EW)

    def add_files(self):
        """添加单个或多个文件"""
        files = filedialog.askopenfilenames(filetypes=[("Python文件", "*.py")])
        for f in files:
            if f not in self.listbox.get(0, tk.END):
                self.listbox.insert(tk.END, f)

    def add_directory(self):
        """添加目录下的所有Python文件"""
        directory = filedialog.askdirectory()
        if directory:
            for root, _, files in os.walk(directory):
                for file in files:
                    if file.endswith(".py"):
                        path = os.path.join(root, file)
                        if path not in self.listbox.get(0, tk.END):
                            self.listbox.insert(tk.END, path)

    def clear_list(self):
        """清空文件列表"""
        self.listbox.delete(0, tk.END)

    def choose_output(self):
        """选择输出目录"""
        path = filedialog.askdirectory()
        if path:
            self.output_path.set(path)

    def choose_icon(self):
        """选择图标文件"""
        file = filedialog.askopenfilename(filetypes=[("图标文件", "*.ico")])
        if file:
            self.icon_path.set(file)

    def start_conversion(self):
        """开始打包"""
        if self.listbox.size() == 0:
            self.log("错误:请先添加要打包的文件!")
            return

        # 获取打包参数
        output_dir = self.output_path.get() or os.getcwd()
        options = []
        if self.onefile.get(): options.append("--onefile")
        if self.noconsole.get(): options.append("--windowed")
        if self.icon_path.get(): options.extend(["--icon", self.icon_path.get()])

        # 启动打包线程
        self.running = True
        self.start_btn.config(state=tk.DISABLED)
        Thread(target=self.run_pyinstaller, args=(output_dir, options)).start()
        self.master.after(100, self.process_queue)

    def run_pyinstaller(self, output_dir, options):
        """执行打包操作"""
        try:
            for file in self.listbox.get(0, tk.END):
                if not self.running: break
                self.update_status(f"正在打包: {os.path.basename(file)}")

                # 构建PyInstaller命令
                cmd = [
                          sys.executable,  # 使用当前Python解释器
                          "-m",
                          "PyInstaller",
                          "--distpath", output_dir,
                          "--noconfirm"
                      ] + options + [file]

                self.log(f"执行命令: {' '.join(cmd)}")

                # 运行并捕获输出
                with subprocess.Popen(
                        cmd,
                        stdout=subprocess.PIPE,
                        stderr=subprocess.STDOUT,
                        encoding='utf-8',  # 强制使用UTF-8编码
                        errors='replace',  # 替换无法解码的字符
                        text=True,
                        bufsize=1
                ) as proc:
                    for line in proc.stdout:
                        self.log(line.strip())

                if proc.returncode == 0:
                    self.log(f"成功打包: {file}\n")
                else:
                    self.log(f"打包失败: {file} (错误码: {proc.returncode})\n")
        finally:
            self.running = False
            self.update_status("打包完成")
            self.start_btn.config(state=tk.NORMAL)

    def log(self, message):
        """记录日志到队列"""
        self.log_queue.put(("log", message))

    def update_status(self, message):
        """更新状态到队列"""
        self.log_queue.put(("status", message))

    def process_queue(self):
        """处理消息队列"""
        while not self.log_queue.empty():
            try:
                msg_type, content = self.log_queue.get_nowait()
                if msg_type == "log":
                    self.log_text.insert(tk.END, content + "\n")
                    self.log_text.see(tk.END)
                elif msg_type == "status":
                    self.status.set(content)
            except queue.Empty:
                pass
        if self.running:
            self.master.after(100, self.process_queue)

print("Python解释器路径:", sys.executable)  # 放在类初始化之后

if __name__ == "__main__":
    root = tk.Tk()
    app = PyToExeConverter(root)
    root.mainloop()

    # 在代码开头添加检查
    import os


我这源码 真的能跑 而且很好用,


10

10

主要是还能批量转换。 我想问问各位大神,怎么把当前的代码打包成一个exe的文件啊

免费评分

参与人数 4吾爱币 +4 热心值 +3 收起 理由
lengz123 + 1 热心回复!
aabbcc123123 + 1 + 1 谢谢@Thanks!
xinxin99 + 1 + 1 谢谢@Thanks!
viklion + 1 + 1 用心讨论,共获提升!

查看全部评分

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

爱飞的猫 发表于 2025-2-14 05:21
dapkouatao1 发表于 2025-2-13 21:08
这代码为什么跟大家的不一样 我第一次发有点懵,

插入代码可以看看教程:

【公告】发帖代码插入以及添加链接教程(有福利)
https://www.52pojie.cn/thread-713042-1-1.html
wsasecy 发表于 2025-2-14 08:50
xiaoye2 发表于 2025-2-14 09:12
nothingnoneqaq 发表于 2025-2-14 09:02
程序员自己裁掉自己
manglang 发表于 2025-2-14 09:49
AI说是控制台模式冲突:使用了 --noconsole 参数但代码依赖控制台输出。
建议调整PyInstaller打包参数,使用以下命令重新打包(重点处理标准流):
pyinstaller --onefile ^
    --add-data="C:\Python39\Lib\site-packages\pywin32_system32\*.dll;./pywin32_system32" ^
    --hidden-import=win32api ^
    --console  # 确保保留控制台输出
    转EXE.py

我用这个方法打包就成功了,只是要开一个看似无用的窗口。
 楼主| dapkouatao1 发表于 2025-2-13 21:08
这代码为什么跟大家的不一样 我第一次发有点懵,

点评

插入代码可以看看教程:  详情 回复 发表于 2025-2-14 05:21
娟然俊逸 发表于 2025-2-14 08:09
nice ! 以后可以借助AI 生成各种简单的小程序了~
lemon395 发表于 2025-2-14 08:57
感谢分享
东莞洪世贤 发表于 2025-2-14 09:06
火钳留名,我昨晚也问了ai这个问题
opacity 发表于 2025-2-14 09:13
现在ds热门程度不亚于刚开始openai出来
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

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

GMT+8, 2026-7-5 15:35

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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