简体   繁体   English

Pyinstaller 生成的文件不起作用

[英]File generated by Pyinstaller does not work

When I use this command on my python code file in windows 10 bash shell:当我在 Windows 10 bash shell 中的 python 代码文件上使用此命令时:

 pyinstaller Test.py

It produces these files (and some others):它生成这些文件(和其他一些文件):

在此处输入图片说明

I'm not sure if the produced file is an .exe file and will work.我不确定生成的文件是否是 .exe 文件并且可以工作。 I cannot run it.我不能运行它。 Could you please help?能否请你帮忙? Thanks.谢谢。

As I see your screenshot you have tried to run the pyinstaller on Linux OS because the generated *.so files are Linux specified shared objects.正如我看到您的屏幕截图,您尝试在Linux操作系统上运行pyinstaller ,因为生成的*.so文件是Linux指定的共享对象。 Furthermore the Test file is a Linux specified executable without extension.此外, Test文件是Linux指定的没有扩展名的可执行文件。

If you want to create an EXE file from your Python file/project, you have to run the pyintaller on a Windows OS.如果要从 Python 文件/项目创建EXE文件,则pyintallerWindows操作系统上运行pyintaller The pyinstaller will collect all needed files Eg.: DLLs, SDKs, etc... pyinstaller将收集所有需要的文件,例如:DLL、SDK 等...

I have copied the below section from PyInstaller official documentation:我从PyInstaller官方文档中复制了以下部分:

PyInstaller is tested against Windows, Mac OS X, and Linux. PyInstaller 已针对 Windows、Mac OS X 和 Linux 进行了测试。 However, it is not a cross-compiler: to make a Windows app you run PyInstaller in Windows;但是,它不是交叉编译器:要制作 Windows 应用程序,您需要在 Windows 中运行 PyInstaller; to make a Linux app you run it in Linux, etc. PyInstaller has been used successfully with AIX, Solaris, and FreeBSD, but is not tested against them.要制作 Linux 应用程序,请在 Linux 等中运行它。 PyInstaller 已成功用于 AIX、Solaris 和 FreeBSD,但未针对它们进行测试。

Some hints how you can create a working EXE file from your Python file/project.一些提示如何从Python文件/项目创建工作EXE文件。

Use the --onefile or -F flag:使用--onefile-F标志:

"In one-file mode, there is no call to COLLECT, and the EXE instance receives all of the scripts, modules and binaries." “在单文件模式下,不调用 COLLECT,EXE 实例接收所有脚本、模块和二进制文件。” Eg.: pyinstaller --onefile test.py例如: pyinstaller --onefile test.py

Use the --windowed or -w flag:使用--windowed-w标志:

Windows and Mac OS X: do not provide a console window for standard i/o. Windows 和 Mac OS X:不为标准 i/o 提供控制台窗口。 On Mac OS X this also triggers building an OS X .app bundle.在 Mac OS X 上,这也会触发构建 OS X .app 包。 This option is ignored in *NIX systems.这个选项在 *NIX 系统中被忽略。

Use the --clean flag:使用--clean标志:

Clean PyInstaller cache and remove temporary files before building.在构建之前清理PyInstaller缓存并删除临时文件。

My recommended command:我推荐的命令:

pyinstaller -Fw --clean test.py

You should run the above command on Windows OS.您应该在Windows操作系统上运行上述命令。

FYI:供参考:

If you have a complex Python project and you have dependencies (required files, folder structure etc...) I recommended to use a *.spec file.如果您有一个复杂的 Python 项目并且您有依赖项(所需文件、文件夹结构等),我建议您使用*.spec文件。 You can read the detail about it on the following link: https://pythonhosted.org/PyInstaller/spec-files.html您可以在以下链接上阅读有关它的详细信息: https : //pythonhosted.org/PyInstaller/spec-files.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM