Import Cython's pyx file in Python
1. Introduction
The Cython’s file namexxx.pyx
needs to import into Python file.
2. Steps
- Generate the
namexxx.so
file:
python setup.py build_ext --inplace
The general content of setup.py
is:
from distutils.core import setup
from Cython.Build import cythonize
import numpy
setup(
include_dirs=[numpy.get_include()],
ext_modules = cythonize(["*.pyx"]),
)
This will generate the build
folder and the namexxx.so
and namexxx.c
files.
- Add these commands into
namexxx.pyx
file
import pyximport
pyximport.install()
- import the right name
import namexxx