4

my structure dictionary is

mainFolder    
    folder1
       __init__.py
       file1.py
       file2.py    
    folder2
       __init__.py
       file3.py
       file4.py    
    setup.py    
    __init__.py

i need import file4.py from folder2 to folder1/file1.py
file1.py:

from ..folder2.file4 import MyClass

and i gets:

SystemError: Parent module '' not loaded, cannot perform relative import

how to fix that ?

Kaker
  • 637
  • 1
  • 11
  • 23

1 Answers1

7

This is because you must to explicitly name the parent package. So in your case you need either from mainFolder.folder2.file4 import Myclass, either from folder2.file4 import Myclass

dgan
  • 1,349
  • 1
  • 15
  • 28