1

Maybe this is a duplicate, but I couldn't find an answer for this particular situation: I want to compile and distribute my python Code to c and then to a binary using gcc. For distribution, I use appimagetool to include libraries.

I use the command

cython3 -3 myapp.py --embed

to create the C code, and then

gcc myapp.c -o myapp $(pkg-config --libs --cflags python3)

to generate the executable. This works, but when I transfer the executable to another machine, I get the error

No Module named AnyRandomModule

Where AnyRandomModule is a python module I am importing. When I install it via

pip3 install AnyRandomModule

it works. But I don't want that the user needs to install the libs himself. How can I bundle my imported python modules in my executable, or otherwise compile them to .so shared library files from which I can import? I already tried to convert them to .so files using the quick start example from the Cython documentation, but I still get the same error when executing the myapp executable, even though those .so files are in the same directory.

Tom Atix
  • 381
  • 1
  • 21

1 Answers1

1

you can use this answer: Building Cython-compiled python code with PyInstaller

to bundle everything together (use cython and then pack everything using pyinstaller which should pack all the packages)

Koko Jumbo
  • 313
  • 1
  • 5
  • I don't want to use Pyinstaller, should have mentioned that. I have a working Pyinstaller setup but I don't want to use it this time because it makes decompilation trivial. – Tom Atix Apr 22 '21 at 13:50
  • Looked at it more intensely... thanks, you pointed me to the right solution. Pyinstaller files are easily decompiled, but if I compile my module as a shared object with cython this bytecode is quite safe. Thanks! – Tom Atix Apr 23 '21 at 00:46