Python: Compile .py to .so
作者:XD / 发表: 2022年3月31日 00:10 / 更新: 2022年3月31日 00:16 / 编程笔记 / 阅读量:1177
1. Set up the environment
pip install cython
yum install python-devel (apt-get install python-devel)
yum install gcc (apt-get install gcc)
2. Create a setup.py file
from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules = cythonize(["your_file_name.py"]))
3. Run this line, the .so file saved in ./build/lib...
python setup.py build_ext
4. Move the .so file to main folder, then import the class or def.
import your_file_name
相关标签