使用pyinstaller在Linux中创建python可执行文件时,无法在Windows机器中运行

2024-03-28 09:59:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经在我的Ubuntu机器上编写了Python脚本,并希望创建可执行文件在Windows机器上运行它们。我测试了pyinstaller,通过执行以下操作来创建可执行文件:

>>> pyinstaller myScript.py

生成的/dist/myScript在创建它的Ubuntu机器上运行良好。你知道吗

但是,将可执行文件传输到windows计算机时,它不会运行。 首先,由于没有.exe扩展名,windows甚至无法将其识别为可执行文件。 手动添加.exe并在cmd上运行后:

>>> myScript.exe 

命令中写道:“这个版本的‘C:\Users\User\Desktop\myScript.exe'与您正在运行的Windows上的版本不兼容。请检查计算机的系统信息,然后与软件发行商联系“

我怎样才能解决这个问题?这是为windows创建python可执行文件的正确方法吗?你知道吗


Tags: py版本脚本cmd机器可执行文件ubuntuwindows
2条回答

只能为当前操作系统创建可执行文件。 因此,您必须在windows上创建可执行文件,使其成为.exe。 您不能简单地更改文件类型以使其在不同的操作系统上运行

Pyinstaller中的Supporting Multiple Operating Systems部分突出显示了您的用例:

If you need to distribute your application for more than one OS, for example both Windows and Mac OS X, you must install PyInstaller on each platform and bundle your app separately on each.

相关问题 更多 >