I want to compile some python libraries I wrote into a single so file using python. The folder structure is like the following:
src/
main.py
packages/
lib1.py
lib2.py
lib3.py
lib4.py
...
__init__.py
(__init__.py
is a blank file)
In the setup I got something like:
cythonize(["src/packages/*.py"])
compile = "gcc -shared -Os -I /usr/include/python2.7 -L /usr/lib/python2.7/config-x86_64-linux-gnu -o packages.so -fPIC src/packages/lib1.c src/packages/lib2.c ... src/packages/__init__.c -lpthread -ldl -lpython2.7"
os.system(compile)
By this way, I got the file packages.so
. But when I import it in python, I got errors trying to use my functions, python says they're not there.
Using:
import packages
print dir(packages)
Prints:
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__test__']
Showing that my functions does not exists in the file. But if I add some function in the __init__.py
it shows it using dir
. I tried importing the others modules (import lib1
and from lib1 import *
) in the __init__.py
file too and didn't works. I'm out of ideas :c .
What am I doing wrong? Is there a way to put it on one single file or will I have to distribute my program with 10 so
files with it?