1

In my hands i have a .pyc and not the corresponding .py or .pyx.

  • Is it possible to cythonize a .pyc ?

  • should it be decompressed to .py first and how ?

kiriloff
  • 25,609
  • 37
  • 148
  • 229

1 Answers1

3

Cython is a superset of Python, and hence you can cythonize a .py file. I say this because .pyc files can be decompiled to .py file. There are several libraries that can do this, however, I would suggest that you have a look at this question asked previously.

Although this can be done, there are no real benefits, your python code can at most gain a 20% speed boost.

Community
  • 1
  • 1
Games Brainiac
  • 80,178
  • 33
  • 141
  • 199
  • thanks. there is no benefit to decompile the pyc to py but there is one gain in speed when i cythonize to C++, right ? – kiriloff Feb 17 '14 at 14:16
  • No, you will not gain any speed. I can explain further, but it will only confuse you. Unless you statically define the types for your data, Cython can do very little optimization. It says so in the [documentation](http://docs.cython.org/src/quickstart/cythonize.html). – Games Brainiac Feb 17 '14 at 14:20
  • http://docs.cython.org/en/latest/src/tutorial/pure.html confirms "pure Python scripts can be compiled with Cython, it usually results only in a speed gain of about 20%-50%." but further explains how to add type annotations in a separate `pxd` file, gaining more speed while keeping a plain `.py` source – azrdev Aug 13 '19 at 15:04