簡體   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