更新时间:2023-11-18 18:44:22
目录不是包,除非它包含 __ init __。py
文件,即使文件为空。因此,将一个空的 __ init __。py
文件添加到 libs
目录中。
A directory is not a package unless it contains a __init__.py
file, even if the file is empty. So add an empty __init__.py
file to the libs
directory.
使用此目录结构,您的 a.pxd
和 b.pyx
, setup.py
和 script.py
(如下),
With this directory structure, your a.pxd
and b.pyx
, setup.py
and script.py
(below),
% tree .
.
├── libs
│ ├── a.pxd
│ └── __init__.py
├── b.c
├── b.pyx
├── b.so
├── build
│ ├── temp.linux-x86_64-2.7
│ │ └── b.o
│ └── temp.linux-x86_64-3.4
│ └── b.o
├── script.py
├── setup.py
运行 script.py
的工作原理:
% python setup.py build_ext --inplace
% python ./script.py
a
setup.py:
setup.py:
# python setup.py build_ext --inplace
from distutils.core import setup
from Cython.Build import cythonize
setup(
name='test',
ext_modules=cythonize("b.pyx"),
)
script.py:
script.py:
import b
b.b()