简体   繁体   English

在C编译的python代码上使用pyinstaller

[英]Using pyinstaller on c compiled python code

I am trying to convert one single c file into an executable with pyinstaller. 我正在尝试使用pyinstaller将单个c文件转换为可执行文件。 Now the reason why I want to compile with pyinstaller is because of the fact, that the exe file is supposed to be run on both a mac as well as a windows machine. 现在我之所以要用pyinstaller进行编译的原因是因为,该exe文件应该在Mac和Windows计算机上都可以运行。

Now, how can this be done? 现在,该怎么办呢?

You can include Cython/C modules in a Pyinstaller executable. 您可以在Pyinstaller可执行文件中包含Cython / C模块。

However, Pyinstaller is not suitable for your goal of making a single executable that works on Mac and Windows. 但是,Pyinstaller不适合您使单个可执行文件在Mac和Windows上都能运行的目标。 From the first question of the Pyinstaller FAQs: 关于Pyinstaller常见问题的第一个问题:

Can I use PyInstaller as a cross-compiler? 我可以使用PyInstaller作为交叉编译器吗? Can I package Windows binaries while running under OS X? 在OS X下运行时可以打包Windows二进制文件吗?

No, this is not supported. 不,不支持。 [...] [...]

It seems like you've fundamentally misunderstood what Pyinstaller does: it packages a Python script with Python and its libraries to allow you to use the Python script without having to install Python separately. 似乎您从根本上误解了Pyinstaller的功能:它将Pyinstaller与Python及其库打包在一起,以允许您使用Python脚本而不必单独安装Python。 To do this though it needs to package a version of Python specific to the platform, and so the executable will only work on the same operating system that it was created on. 为此,尽管它需要打包特定于该平台的Python版本,所以该可执行文件只能在其创建时所在的同一操作系统上工作。

In addition, it deals with compiled libraries (like Cython modules) by zipping them up and the extracting them into a temporary folder when run . 此外,它还通过压缩编译的库(例如Cython模块)来处理它们,并在运行时将其解压缩到一个临时文件夹中 Therefore, even if Pyinstaller somehow managed to bundle two versions of Python to work on both Windows and Mac your C compiled module would still only be compiled for a single platform, so by doing it they way you describe you've actually made your code less portable. 因此, 即使 Pyinstaller以某种方式设法将两个版本的Python捆绑在一起在Windows和Mac上运行,您的C编译模块仍将仅针对单个平台进行编译,因此通过这样做,您描述的方式实际上使代码减少了便携式的。

I don't believe there are any obvious tools to do what you're asking. 我不相信有任何明显的工具可以满足您的要求。

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

相关问题 使用 PyInstaller 构建 Cython 编译的 Python 代码 - Building Cython-compiled python code with PyInstaller 使用 pyinstaller 编译的 python 模块运行 celery worker - Run celery worker with a compiled python module compiled using pyinstaller 从python GUI使用C编译代码 - Using C compiled code from python GUI 使用 PyInstaller 将 Cython 编译的模块和 python 代码构建为可执行二进制文件 - Build Cython-compiled modules and python code into executable binary using PyInstaller 在 powershell 中运行 Python 可执行文件(使用 pyinstaller 编译)并将 output 保存在变量中 - Run Python excutable ( compiled using pyinstaller ) in powershell and save the output in variable Pyinstaller编译的可执行文件失败并显示139退出代码 - Pyinstaller compiled executable fails with 139 exit code 带有python代码pyinstaller的子文件夹 - Subfolders with python code pyinstaller Python:使用pyinstaller,cx_freeze或p2exe编译为exe时,ftfy导致应用程序崩溃 - Python: ftfy causes app crash when compiled to exe using pyinstaller, cx_freeze or p2exe 使用模块编译的Python代码的版本兼容性 - Compatibility of versions for compiled Python code using modules 如何运行使用 python 编译的 C - How to run a C compiled using python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM