0

My directory structure is like:

example1(folder)
    - util.pyd(file)
    - high.pyd(file)
example2(folder)
    -main_file.py(file)

Here, util.pyd and high.pyd files are in cython.

In addition, util.pyd is parent of high.pyd.

That means it uses a class of util.pyd as an object of its class. And then main_file.py imports classes from both util.pyd and high.pyd.

The issue what I am facing is:

In main_file.py, it imports class from Util.pyd correctly, but importing class from high.pyd, it is unable to find util.

danny
  • 5,140
  • 1
  • 19
  • 31
  • Do you have it working with non-Cython python files (i.e. you look to be doing something like [this](https://stackoverflow.com/questions/30669474/beyond-top-level-package-error-in-relative-import))? Cython should be the same (hopefully) so if you can get it working with .py files that would be a good start. – DavidW Apr 13 '18 at 20:21
  • Thank you for your response. Yes it is working for .py files. And the problem is just when two of them are in cython and the main file is in python – Lohitha Chintham Apr 15 '18 at 14:34

1 Answers1

0

The following minimum, complete example works for me:

example2/main_file.py

from example1 import high

example1/util.pyx

class U:
    pass

example1/high.pyx

from . import util

class C(util.U):
    pass

I compiled util.pyx and high.pyx by changing to directory example1 and doing cythonize -i util.pyx and cythonize -i high.pyx

From the directory containing "example1" and "example" I ran python3 -m example2.main_file (which is the appropriate way to run a submodule as a script).


If this isn't enough information to get your code working I would suggest you edit your question to show exactly what you did.

DavidW
  • 29,336
  • 6
  • 55
  • 86