Pycharm: "unresolved reference" error on the IDE when opening a working project

Sergio Ayestarán picture Sergio Ayestarán · Dec 9, 2013 · Viewed 58.4k times · Source

Intro

I have a Python project on a git repository. Everything works ok for most of the team members, we can sync the code and edit it without any problem with Pycharm on different platforms (Windows, Linux)

The problem

On one of the computers we are getting "Unresolved reference" all over the code on almost every import with the exception of Python's built in libraries (i.e. import datetime is working). This computer is running the Mac version of Pycharm.

The question

Anyone knows how to solve this?, since most of the imports are not recognized code completion and navigation trough goto->declaration and so on is not working. Is there any known issue with the Mac version?

Thanks in advance!

Answer

einnocent picture einnocent · Dec 9, 2013

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