1

Here is my code directory and main.py is the file I run the execute the whole code

Above I shared my code directory and "main.py" is the file that runs the whole code.

Here is the process I followed:

Commands to build code for linux

1. cython --embed -o main.c main.py

2. gcc -v -Os -I /home/user/anaconda2/envs/packaging/include/python3.6m -L /home/user/anaconda2/envs/packaging/lib -o app_package.so main.c -lpython3.6m -lpthread -lm -lutil -ldl

I get binary with name "app_package.so" which runs perfectly in same directory of code. But when I copy the binary to any other directory it throws an error

unable to import "verification.py" file

Which means it only compiled main.py and doesn't know about the other packages (e.g. verification.py)

Please help me to understand how can I generate a standalone binary executable of python code with all the dependencies.

Nomiluks
  • 2,052
  • 5
  • 31
  • 53
  • `Please help me to understand how can I generate a standalone binary executable of python code with all the dependencies.` Python is a scripting language and is not meant to be compiled into a single executable. Cython allows you to bridge to compiled languages by defining modules that use compiled code. It does not turn python into C like language. I therefore highly doubt that this is possible. – cel Apr 12 '19 at 07:20
  • Yes argument is valid, but i want to convert my code into `C` using cython and then build *.so file by compiling the `C` code into executable binary. So, I want to build single binary file from `C` code generated by Cython. – Nomiluks Apr 12 '19 at 07:28
  • But that still depends on libpython.so, so you need to link that in statically. And it still (probably) depends on large chunks of the Python standard library (mostly, but not entirely, written in Python). It rapidly becomes very difficult – DavidW Apr 12 '19 at 08:20

0 Answers0