python – Unresolved reference issue in PyCharm

python – 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 dont have to hard code things into your interpreters settings:

  • Add src as a source content root:

                           
enter

  • Then make sure to add add sources to your PYTHONPATH under:

    Preferences ~ Build, Execution, Deployment ~ Console ~ Python Console
    

enter

  • Now imports will be resolved:

                     
enter

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:

                                 
enter

After all this dont forget to restart. In PyCharm menu select: File –> Invalidate Caches / Restart

  1. check for __init__.py file in src folder
  2. add the src folder as a source root
  3. Then make sure to add add sources to your PYTHONPATH (see above)
  4. in PyCharm menu select: File –> Invalidate Caches / Restart

python – Unresolved reference issue in PyCharm

If anyone is still looking at this, the accepted answer still works for PyCharm 2016.3 when I tried it. The UI might have changed, but the options are still the same.

ie. Right click on your root folder –> Mark Directory As –> Source Root

Leave a Reply

Your email address will not be published.