简体   繁体   English

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

[英]Creating a python executable in Linux with pyinstaller, fails to run in a Windows machine

I have written Python scripts on my Ubuntu machine, and would like to create executables to run them on Windows machines. 我已经在Ubuntu计算机上编写了Python脚本,并希望创建可执行文件以在Windows计算机上运行它们。 I tested pyinstaller to create an executable by doing: 我通过执行以下操作测试了pyinstaller以创建可执行文件:

>>> pyinstaller myScript.py

The resulting /dist/myScript runs fine on the Ubuntu machinie it was created. 生成的/ dist / myScript在创建的Ubuntu机器上运行良好。

However when transfering the executable to a windows computer it won't run. 但是,当将可执行文件传输到Windows计算机时,它将无法运行。 First of all, not having the .exe extension, windows does not even recognize it as an executable. 首先,由于没有.exe扩展名,因此Windows甚至无法将其识别为可执行文件。 After manually adding .exe and running on cmd: 手动添加.exe并在cmd上运行后:

>>> myScript.exe 

the cmd spits: " This version of 'C:\\Users\\User\\Desktop\\myScript.exe' is not compatible with the version on Windows you're running. Check your computer's system information and then contact the software publisher " cmd吐出:“此版本的'C:\\ Users \\ User \\ Desktop \\ myScript.exe'与您正在运行的Windows上的版本不兼容。请检查计算机的系统信息,然后与软件发行商联系“

How can I solve this? 我该如何解决? Is this even the correct approach to create a python executable for windows? 这甚至是为Windows创建python可执行文件的正确方法吗?

You can only create an executable for your current operating system. 您只能为当前操作系统创建可执行文件。 So you would have to create your executable on windows for it to be an .exe. 因此,您必须在Windows上创建可执行文件才能使其成为.exe。 You cannot simply change the file type to make it run on a different OS 您不能简单地更改文件类型以使其在其他操作系统上运行

Supporting Multiple Operating Systems section in Pyinstaller highlights your usecase: Pyinstaller中的“ 支持多种操作系统”部分重点介绍了您的用例:

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. 如果您需要为多个操作系统(例如Windows和Mac OS X)分发应用程序,则必须在每个平台上安装PyInstaller并在每个平台上单独捆绑应用程序。

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

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