什么是__init__.py一个Python源目录?
我正在尝试在 cython 中使用显式相对导入。从发行说明看来,相对导入应该在 cython 0.23 之后工作,而我将 0.23.4 与 python 3.5 一起使用。但是我收到了这个奇怪的错误,我找不到很多引用。错误仅来自 cimport:
driver.pyx:4:0: relative cimport beyond main package is not allowed
Run Code Online (Sandbox Code Playgroud)
目录结构为:
myProject/
setup.py
__init__.py
test/
driver.pyx
other.pyx
other.pxd
Run Code Online (Sandbox Code Playgroud)
看起来我可能在 setup.py 中搞砸了,所以我包含了下面的所有文件。
setup.py
driver.pyx:4:0: relative cimport beyond main package is not allowed
Run Code Online (Sandbox Code Playgroud)
driver.pyx
#!/usr/bin/env python
from . import other
from . cimport other
Run Code Online (Sandbox Code Playgroud)
other.pyx
#!/usr/bin/env python
HI = "Hello"
cdef class Other:
def __init__(self):
self.name = "Test"
cdef get_name(self):
return self.name
Run Code Online (Sandbox Code Playgroud)
other.pxd
cdef class Other:
cdef get_name(self)
Run Code Online (Sandbox Code Playgroud)
我已经试过移动 …