Hello. I, like many, do not want to just write Python code, I want to also make EXE applications. I have already achieved a lot, wrote the application on Pygame, compiled it into EXE, did the NSIS installer. However, the problem of open source has been hanging over me - anyone can take decompyle and pick up my .PYC files. And then Cython came to the rescue (not to be confused with CPython), which is compiled into a DLL (PYD) and not decompiled (the champion in opening sources with the help of a decompiler still opens it, but the chance is still very small). The trick is that I did everything as instructed, but "not growing in the garden" - gave an error. Here is my Cython compiler script:

from distutils.core import setup from Cython.Build import cythonize setup( name = 'JoyMonitorMain', ext_modules = cythonize("joymonitor.pyx"), ) 

And here is the error:

 joymonitor.pyx:16:12: Expected an identifier Traceback (most recent call last): File "cythonise.py", line 6, in <module> ext_modules = cythonize("joymonitor.pyx"), File "C:\Program Files\Python34\lib\site-packages\Cython\Build\Dependencies.py", line 934, in cythonize cythonize_one(*args) File "C:\Program Files\Python34\lib\site-packages\Cython\Build\Dependencies.py", line 1056, in cythonize_one raise CompileError(None, pyx_file) Cython.Compiler.Errors.CompileError: joymonitor.pyx 

I ran the compilation script on the command line with the command:

python cythonise.py build_ext --inplace


Just in case, I will say that I did not use Cython earlier. And in my code, there may be some nonsense for C, which is the syntax of Python 3, for example, the string literals 'замечательная строка про погоду' instead of "замечательная строка про погоду" . Does it matter to cython?


I checked the code and read the documentation - my code is compatible with Cython. But I still do not understand what kind of error? What doesn't he like?

  • and if you just use py2exe? - nick_gabpe
  • @nick_gabpe I heard about some conventions, inconveniences and tricks with py2exe. cx_Freeze was originally developed as the "next step in evolution" of py2exe and the built-in utility Freeze. I have experience with cx_Freeze, but not with py2exe. - Vladislav Toncharov
  • I will gamble: as a rule, your code is not needed by anyone, and they are unlikely to be hacked, and if they really want to, nothing will help. It's really possible to protect your code from hacking only by executing it on the server :) - gil9red
  • In any case, DLLs and PYCs are not the easiest victim to crack. - Vladislav Toncharov
  • Surprisingly, I noticed the first line of a traceback almost a month after the question existed! Why does a python like to swear so much at the definition of functions in a class with a name identical to the name of one of the built-in functions (line 16 - such a definition in a class)? I also noticed that if you simply open the code on the command line with automatic selection of a suitable program, then it gives an error, and if you run it via python (specified in the PATH), then there is no error! - Vladislav Toncharov

1 answer 1

In fact, the problem was in the first line of the error:

 joymonitor.pyx:16:12: Expected an identifier 

This is such an imperceptible system to produce errors of sitonization. Yes, so imperceptibly: this first line is simply imperceptible when you run around your eyes on traceback. As a fan of Visual Studio, C # and .NET (in addition to pure Python), this is puzzling to me. But still it is a re raise with an entry in stderr , this cannot be readable. When using Cython, this translation error output needs to be considered. After eliminating the error, of course, the sitonizer earned.