繁体   English   中英

如何将导入 c 的 python 代码转换为 exe 文件?

[英]How do I convert a python code importing c to an exe file?

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

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 库?

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

暂无
暂无

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

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