This problem has been driving me nuts. I am trying to import a class from a file in the same directory. PyCharm is giving me the \"Unresolved reference\" error. MyClas
If MyClass
is defined in pack/file.py
, you need to import it as:
from pack.file import MyClass
Note that using names of Python built-in types (such as file
) for your own modules is a bad idea.
The following steps solved my issues:
If you are using python version 3 try this
from .pack import myclass
This worked for me
I had the same issue when I tried to import a new class, however I could successfully import functions from a file in the same directory. I still dont understand why I could not import my class but thought I would share the information for other users.
@kaylebs response worked for me. However I then added the src directory to the list of source directories, first link in @lulian 's question and could remove the '.' from my file name.
Yes, if you are using python 3 you should add something like this:
from .pack import MyClass
It will work