作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的项目具有以下目录结构:
.
├── Makefile
├── pxd
├── pyx
│ ├── Landscaping.pyx
│ ├── Shrubbing.pxd
│ └── Shrubbing.pyx
└── setup.py
Shrubbing.pxd
在其他任何地方,比如说,进入
pxd/
,我收到以下错误:
Error compiling Cython file:
------------------------------------------------------------
...
import pyx.Shrubbing
cimport Shrubbing
^
------------------------------------------------------------
pyx/Landscaping.pyx:2:8: 'Shrubbing.pxd' not found
Error compiling Cython file:
------------------------------------------------------------
...
import pyx.Shrubbing
cimport Shrubbing
cdef Shrubbing.Shrubbery sh
^
------------------------------------------------------------
setup.py
我有:
from distutils.core import setup, Extension
from Cython.Build import cythonize
setup(ext_modules=cythonize([
Extension(
'pyx.Landscaping',
sources=["pyx/Landscaping.pyx"],
include_dirs=['pxd']), # <-- HERE
Extension('pyx.Shrubbing', sources=["pyx/Shrubbing.pyx"])
]))
Shrubbing.pxd
的新目录.
最佳答案
include_dirs
用于 C/C++ 头文件,而不是 Cython pxd
文件。
一般情况下最好保持相关pyx/pxd
文件放在同一个目录下,即 Shrubbing.pyx 和 Shrubbing.pxd 应该在同一个目录下。
然后从其他模块使用它,包括 __init__.pxd
和 cimport
通过扩展中使用的名称,例如 pyx.Shrubbing
就像使用 Python 模块一样。
如果在 python 中导入(不是 cimport
),__init__.py
也应该包括在内。
在同一模块中使用时,OTOH,.pxd
需要在该模块的运行时可用,这意味着将其包含在 Python 搜索路径中。
如果要将 pxd 文件组织到单独的目录中,则将它们符号链接(symbolic link)到模块目录中以使它们可用于模块,该目录包含 __init__.pxd
或 .py
文件。
这有点困惑,因为 Cython 目前不支持相对导入,因此在想要从另一个目录导入时需要链接。
见 documentation for more details .
关于cython - 如何在 Cython 中指定 `.pxd` 文件的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47361418/
我是一名优秀的程序员,十分优秀!