Linux command
cython 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Compile a Cython file
cython [module.pyx]
Compile with Python 3
cython -3 [module.pyx]
Generate C++ code
cython --cplus [module.pyx]
Compile with annotations
cython -a [module.pyx]
Specify output filename
cython -o [output.c] [module.pyx]
Embed the Python interpreter
cython --embed [module.pyx]
说明
Cython is a programming language and compiler that translates Python-like code to C or C++. It enables writing C extensions for Python with Python syntax, providing significant performance improvements over pure Python. The compiler takes .pyx files (Cython source) and produces C or C++ files that can be compiled into Python extension modules. Cython code can include both Python and C type declarations, enabling fine-grained optimization. The annotation mode (-a) is particularly useful for optimization, generating an HTML report showing which lines generate Python API calls versus pure C code, with color-coding to highlight slow paths.
参数
- -o _FILE_
- Specify output C/C++ file name.
- -3, --3
- Use Python 3 syntax and semantics.
- -2, --2
- Use Python 2 syntax and semantics.
- --cplus
- Generate C++ code instead of C.
- -a, --annotate
- Generate annotated HTML showing Python/C interaction.
- --embed _MAIN_
- Generate a main() function to embed Python.
- -I _DIR_, --include-dir _DIR_
- Add include directory.
- -w, --working _DIR_
- Set working directory.
- --line-directives
- Emit source line directives.
- -X _NAME=VALUE_
- Set compiler directive.
FAQ
What is the cython command used for?
Cython is a programming language and compiler that translates Python-like code to C or C++. It enables writing C extensions for Python with Python syntax, providing significant performance improvements over pure Python. The compiler takes .pyx files (Cython source) and produces C or C++ files that can be compiled into Python extension modules. Cython code can include both Python and C type declarations, enabling fine-grained optimization. The annotation mode (-a) is particularly useful for optimization, generating an HTML report showing which lines generate Python API calls versus pure C code, with color-coding to highlight slow paths.
How do I run a basic cython example?
Run `cython [module.pyx]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -o _FILE_ do in cython?
Specify output C/C++ file name.