'cannot find cimported module' with subfolder #1718

Open
xatian opened this Issue May 27, 2017 · 0 comments

Comments

Projects
None yet
1 participant

xatian commented May 27, 2017 edited

I basically got these files:
src/header.pxd

cdef extern from "<stdio.h>":
    int printf (const char*, ...)

src/main.pyx

cimport header
def myFunc ():
    header.printf ("Hello World\n")

setup.py

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize

ext_modules = [
    Extension ("*", sources = ["src/main.pyx"], include_dirs = ['.'])
]
setup (
  name = "blabla",
  ext_modules = cythonize (ext_modules),
  script_args = ['build_ext'],
  options = {'build_ext': { 'inplace':True } }
)

Now if I run this I get this output:

>>> python setup.py
src/main.pyx: cannot find cimported module 'header'
running build_ext
building 'main' extension
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Os -fomit-frame-pointer -fPIC -I. -I/usr/include/python3.5m -c src/main.c -o build/temp.linux-x86_64-3.5/src/main.o
gcc -shared -Wl,--as-needed build/temp.linux-x86_64-3.5/src/main.o -L/usr/lib -lpython3.5m -o /home/programming/python/main.cpython-35m-x86_64-linux-gnu.so

The warning makes no sense to me since importing the module and calling myFunc works fine.
If I put main.pyx and header.pxd in the same directory as setup.py the warning goes away.
What am I missing here?

If I add a empty __init__.py - file to the src-directory the warning goes away but then I cannot import any global module in main.pxy ... So when I add the init-file and change main.pxy to this

cimport header
import sys
def myFunc ():
    header.printf ("Hello World\n")
    print (sys.version)

I get this this error when importing the module:

Python 3.5.2 (default, Dec 22 2016, 10:15:38) 
[GCC 6.2.1 20160822] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import main
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "src/main.pyx", line 4, in init src.main (src/main.c:1050)
    import sys
SystemError: Parent module '' not loaded, cannot perform relative import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment