0

I have a Django application that will be distributed soon on a client server and I don't want to provide access to my source code.

Someone suggested to me the use of Cython in order to compile my project into .so modules that will prevent the reverse engineering of my source code.

I tried setting up the setup.py files and running a compilation and I was able to obtain the .so files, but the problem is that every time I was hit by the problem of " undefined symbol: _Py_ZeroStruct " after deleting the .py files from the project, leaving the new .so files and running my Django project.

The Setup.py is written as follow :

from distutils.core import setup
from Cython.Build import cythonize

setup(ext_modules= cythonize( ['appFolder/*.py', 'MainProjectFolder/*.py'] ) )

So I am asking you guys if there anyone who tried compiling his project with Cython and how did he wrote the setup.py in order to be able to run Django project successfully.

  • You can use pyinstaller to create a single bundle – geckos Apr 14 '19 at 00:39
  • Thanks for the suggestion, but is it imposible to do it with cython ? – Yasser Kotrsi Apr 14 '19 at 01:19
  • I don't know if is impossible but pyinstaller would easier. I did this before for windows machine (built from a mac) it create a single binary file. It would be possible to use cythonize but I don't think that it will solve all your problems. – geckos Apr 14 '19 at 01:45
  • Thanks a lot. I think I figure out the solution with Cython, actually I was compiling with Python3 and than running the Django project with Python2 which, somehow, produced this problem of undefined symbol. – Yasser Kotrsi Apr 14 '19 at 01:50
  • https://stackoverflow.com/questions/3539120/using-cython-with-django-does-it-make-sense https://stackoverflow.com/questions/32577864/cython-for-a-django-app-would-it-work – DavidW Apr 14 '19 at 06:58

1 Answers1

2
  • The error mentioned " undefined symbol: _Py_ZeroStruct " is due to compiling the modules with Python3 and than running the Django project with Python2 so the import of the modules won't work as the shared objects .so won't be recognized based on the symbol table of the interpreter.
  • Also I have compiled every package in my project except the main project directory which contains ['settings.py', 'urls.py', 'wsgi.py', ].

  • Another problem jumped up to my screen saying that the app containing my compiled models modules (the old models.py) isn't recognized as a correct App model:

 RuntimeError: Model class ..models. doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

So I just added in my models.py in each class :

class Meta :
    app_label = "app-name"

I hope that this will solve a part of the problems during your compilation. Good luck.