【问题标题】:How do I convert a python code importing c to an exe file?如何将导入 c 的 python 代码转换为 exe 文件?
【发布时间】:2022-08-03 07:20:33
【问题描述】:

我目前正试图让我的项目作为可执行文件工作,以便我可以更轻松地共享它,但是所涉及的代码导入了一些 c 代码以使用 ctypes 库提高速度。我正在使用 pyinstaller 来生成我的 .exe,它工作正常,除了 CDLL ctype 函数,如下面的代码所示:

from ctypes import CDLL
import time

foo_lib_path = \'theories/foo.so\'
foo = CDLL(foo_lib_path)
print(\'Mission accomplished\')
time.sleep(10)

当我在正常环境中运行此代码时,它可以正常工作,但是当我使用 pyinstaller --onefile \'bar.py\'pyinstaller --hidden-import \'theories/foo.so\' --onefile \'bar.py\' 编译为 exe 时,它​​会立即中断。我如何解释在我的代码中导入 c 库?

    标签: python c import pyinstaller exe


    【解决方案1】:

    我最终为遇到相同问题的任何未来用户找到的解决方案是将命令--add-binary 'theories/foo.so;.' 添加到--onefile 而不是--hidden-import 'theories/foo.so'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-21
      • 2020-03-26
      • 2014-03-24
      • 1970-01-01
      • 1970-01-01
      • 2012-05-07
      相关资源
      最近更新 更多