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

Question:

I am currently trying to get my project to work as an executable so I can share it more easily, but the code involved imports some c code to improve speed using the ctypes library. I am using pyinstaller to produce my .exes and it’s working fine except with the CDLL ctype function, as in the code below:

from ctypes import CDLL
import time

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

When I run this code in my normal environment it works fine but when I compile to exe using pyinstaller --onefile 'bar.py' or pyinstaller --hidden-import 'theories/foo.so' --onefile 'bar.py' it immediately cuts out. How can I account for importing c libraries in my code?

Asked By: Arkleseisure

||

Answers:

The solution I eventually found for any future users with the same problem was to add the command --add-binary 'theories/foo.so;.' to --onefile instead of --hidden-import 'theories/foo.so'.

Answered By: Arkleseisure
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.