我希望我的 python GUI 应用程序可以在所有三个操作系统上运行,而无需在每个平台上重新编译。 pyinstaller(通过或类似实用程序)创建的 python 可执行文件是否像 Java 的字节码一样独立于平台? Java 的字节码使用 JRE 在 Windows、Mac 和 Linux 上运行。
最佳答案
它就在 documentation 中
The output of PyInstaller is specific to the active operating system and the active version of Python. This means that to prepare a distribution for:
- a different OS
- a different version of Python
- a 32-bit or 64-bit OS
you run PyInstaller on that OS, under that version of Python. The Python interpreter that executes PyInstaller is part of the bundle, and it is specific to the OS and the word size.
换句话说:不,它不可移植。您需要针对每个平台/架构进行编译。
正如@juanpa.arrivillaga 在评论中所述,这与 python 通常执行的字节码无关。 是便携的。这里的问题是 PyInstaller 捆绑了一个特定于操作系统和体系结构的 python 解释器(也就是说,这不起作用,原因与您通常无法在 MacO 上运行 Windows 可执行文件的原因相同)。
关于Python 与 Java 字节码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68098666/