I have a directory structure
├── simulate.py
├── src
│ ├── networkAlgorithm.py
│ ├── ...
And I can access the network module with sys.path.insert()
.
import sys
import os.path
sys.path.insert(0, "./src")
from networkAlgorithm import *
However, pycharm complains that it cannot access the module. How can I teach pycham to resolve the reference?
Generally, this is a missing package problem, just place the caret at the unresolved reference and press
Alt+Enter
to reveal the options, then you should know how to solve it.pycharm uses venv ,in the venv u should install the packages explicitly or goto settings ->project interpreter ->add interpreter ->inherit global site-packages
After following the accepted answer, doing the following solved it for me:
File
→Settings
→Project <your directory/project>
→Project Dependencies
Chose the directory/project where your file that has unresolved imports resides and check the box to tell Pycharm that that project depends on your other project.
My folder hierarcy is slightly different from the one in the question. Mine is like this
Telling Pycharm that src depends on
MyDirectory
solved the issue for me!__init__.py
file insrc
foldersrc
folder as a source rootPYTHONPATH
(see above)After testing all workarounds, i suggest you to take a look at
Settings -> Project -> project dependencies
and re-arrange them.Many a times what happens is that the plugin is not installed. e.g.
If you are developing a django project and you do not have django plugin installed in pyCharm, it says error 'unresolved reference'. Refer: https://www.jetbrains.com/pycharm/help/resolving-references.html