如何仅使用库中需要的部分将 python 转换为 exe?

发布于 2025-01-16 21:30:28 字数 302 浏览 2 评论 0原文

我制作了一个简单的脚本,将其转换为 exe,但使用 auto py to exe 在一种目录模式下的最终输出为 170 mb,在一种文件模式下为 64 mb。太疯狂了,无论如何我只能复制我的脚本需要的库部分?

编辑:我的脚本很简单, 就是这样 这些库是 tkinter、keyboard、pyautogui、pywinauto 和 time。

I made a simple script, turned it into an exe but the final output using auto py to exe with one directory mode was 170 mb, with one file mode it was 64 mb. Thats insane, anyway I can only copy the parts of libraries that my script needs?

EDIT: My script is simple, this is it The libraries are tkinter, keyboard, pyautogui, pywinauto and time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

星光不落少年眉 2025-01-23 21:30:28

您可以创建一个虚拟环境,在其中安装所需的模块,然后在该环境本身中创建 exe 文件。无论如何,Python 基础库都会在那里。查看:如何在 pyinstaller 中仅包含所需的模块?

You could create a virtual environment where you can install your required modules and then create the exe file in that environment itself. The python base library would be there anyway. Check out : How to include only needed modules in pyinstaller?

恋竹姑娘 2025-01-23 21:30:28

使用pyinstaller将python文件转换为exe。

安装:pip install pyinstaller

转换(在终端中):pyinstaller --onefile“path_to_file.py”

这将在您运行代码的目录中创建一个“dist”文件夹它将包含 python 文件的“.exe”文件,这只安装程序中使用的模块。

但不幸的是,由于使用的模块,exe 文件的大小通常很大,并且无济于事(在我看来)

Use pyinstaller to convert python files to exe.

Installation: pip install pyinstaller

Convert (in Terminal): pyinstaller --onefile "path_to_file.py"

This would create a "dist" folder in the directory you ran the code in and it would contain the ".exe" file of the python file, this only installs the modules used in the program.

But unfortunately, Size of exe Files are usually big due to the modules used, and cannot be helped (in my opinion)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文