Reputation: 716
If I have a module in my project with all the inits configured properly and I try to import anything from this module, PyCharm does not identify what I am trying to import. It would work before but somehow it stopped working and I have no idea why.
Example:
./package/file.py
def function():
print('function')
./package/__init__.py
from .file import function
./call.py
from package import function
function()
The code executes fine but I can't use auto complete and the editor is informing an error "Unresolved reference 'function'" in the file ./call.py
Methods I tried that did not work:
EDIT0:
If I use import package
the autocomplete works fine displaying the functions (package.function
) to use while in the Python Console, but still doesn't work in the editor.
EDIT1: I tried to mark the directory as Source Root and it did not work
EDIT2: Tried uninstalling from snap and installing it all back again after removing all files from /home/usr/.PyCharm* and it is working fine.
Upvotes: 1
Views: 204
Reputation: 716
Tried uninstalling from snap and installing it all back again after removing all files from /home/usr/.PyCharm* and it worked fine.
Upvotes: 0
Reputation: 6071
You need to mark top level directory as a Source Root
.
Right-Click on it, and at the bottom there is an option Mark Directory as
and choose Sources Root
. It will turn blue.
Then you can import:
from package import function
function()
OR
import package
package.function()
Read more at here.
Upvotes: 1