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

I have the following directory:

myProgram
└── app
    ├── __init__.py
    ├── main.py 
    └── mymodule.py

mymodule.py:

class myclass(object):

def __init__(self):
    pass

def myfunc(self):
    print("Hello!")

main.py:

from .mymodule import myclass

print("Test")
testclass = myclass()
testclass.myfunc()

But when I run it, then I get this error:

Traceback (most recent call last):
  File "D:/Users/Myname/Documents/PycharmProjects/myProgram/app/main.py", line 1, in <module>
    from .mymodule import myclass
SystemError: Parent module '' not loaded, cannot perform relative import

This works:

from mymodule import myclass

But I get no auto completion when I type this in and there is a message: “unresolved reference: mymodule” and “unresolved reference: myclass”. And in my other project, which I am working on, I get the error: “ImportError: No module named ‘mymodule’.

What can I do?

Leave a Comment