Is it possible to compile Python natively (beyond pyc byte code)?

后端 未结 4 1699
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-02 16:39

I wonder if it is possible to create an executable module from a Python script. I need to have the most performance and the flexibility of Python script, without needing to run

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-02 17:03

    I've had a lot of success using Cython, which is based on and extends pyrex:

    Cython is a language that makes writing C extensions for the Python language as easy as Python itself. Cython is based on the well-known Pyrex, but supports more cutting edge functionality and optimizations.

    The Cython language is very close to the Python language, but Cython additionally supports calling C functions and declaring C types on variables and class attributes. This allows the compiler to generate very efficient C code from Cython code.

    This makes Cython the ideal language for wrapping for external C libraries, and for fast C modules that speed up the execution of Python code.

提交回复
热议问题