如何仅使用库中需要的部分将 python 转换为 exe?
我制作了一个简单的脚本,将其转换为 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以创建一个虚拟环境,在其中安装所需的模块,然后在该环境本身中创建 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?
使用
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)