PyCharm shows unresolved references error for valid code
File | Invalidate Caches... and restarting PyCharm helps.
Unresolved reference issue in PyCharm
Manually adding it as you have done is indeed one way of doing this, but there is a simpler method, and that is by simply telling pycharm that you want to add the src
folder as a source root, and then adding the sources root to your python path.
This way, you don't have to hard code things into your interpreter's settings:
- Add
src
as a source content root:
Then make sure to add add sources to your
PYTHONPATH
under:Preferences ~ Build, Execution, Deployment ~ Console ~ Python Console
- Now imports will be resolved:
This way, you can add whatever you want as a source root, and things will simply work. If you unmarked it as a source root however, you will get an error:
After all this don't forget to restart. In PyCharm menu select: File --> Invalidate Caches / Restart
Pycharm: unresolved reference error on the IDE when opening a working project
The key is to mark your source directory as a source root. Try the following:
- In the Project view, right-click on the Python source directory
- In the dialog menu select Mark Directory As > Source Root
The folder should now appear blue instead of beige, to indicate it is a Python source folder.
You can also configure this in PyCharm preferences by doing the following for a project that is already in PyCharm:
- In the Mac toolbar, select PyCharm > Preferences
- In the window that opens, select Project Structure from the menu pane on the left
- Select your project in the middle pane, if necessary
- Right-click on your Python source in the right pane and select Sources from the menu dialog
PyCharm unresolved reference for module members
I opened a ticket with JetBrains support, and after a long investigation they found the issue.
Somehow my __init__.py
files got associated with text files, and that broke the resolver. I fixed it by going to Settings | Editor | File Types | Text | Registered patterns and deleting __init__.py
from the registered patterns.
Thank you JetBrains for the great support!
Related Topics
Tutorial or Guide for Scripting Xcode Build Phases
Is There Something Wrong with This Python Code, Why Does It Run So Slow Compared to Ruby
Python Equivalent of Ruby's 'Method_Missing'
And' (Boolean) VS '&' (Bitwise) - Why Difference in Behavior with Lists VS Numpy Arrays
Visibility of Global Variables in Imported Modules
What Are the Risks of Running 'Sudo Pip'
How to Convert a String to a Number If It Has Commas in It as Thousands Separators
Calling Parent Class _Init_ with Multiple Inheritance, What's the Right Way
Print List Without Brackets in a Single Row
"Ssl Module in Python Is Not Available" When Installing Package with Pip3
Custom Sorting in Pandas Dataframe
Are Python Variables Pointers? or Else, What Are They
Security of Python's Eval() on Untrusted Strings