Reputation: 5890
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?
Upvotes: 65
Views: 87639
Reputation: 23
Had this problem with OpenCV and none of these answers worked.
The only solution that did was adding the OpenCV folder path to the interpreter. This solution explains all the steps: This Solution
Upvotes: 0
Reputation: 18980
PyCharm > select "File" menu > select "Invalidate Caches / Restart" menu option
Upvotes: 1
Reputation: 1883
My ten-penneth - If you're working with virtual environments (have a venv
directory) make sure it is marked as excluded.
Plagiarised from above:
venv
directoryThe directory should turn orange...
This sometimes happens if you've done a git clean
or for whatever reason had to rebuild your environment and PyCharm hasn't noticed
Upvotes: 1
Reputation: 1092
I faced similar issue with pyspark ( spark 2.1 ) & luigi.
Failed tries:
Unresolved reference pyspark
could be fixed by adding the spark's python directory as Content Root in the project, but running the project as luigi task gave the same error.
Successfull steps
__init__.py
file in the projectInclude following lines of code at the top of script
...
import sys
sys.path.append("/path/to/spark/python")
sys.path.append("/path/to/spark/python/lib")
...
// import pyspark files after above mentioned lines
and the Unresolved reference error issue was fixed both in pycharm & luigi task.
Upvotes: 1
Reputation: 520
PyCharm - Alt-F(ile); Settings; Project Structure; click +Add content root; point your folder containing the package in contention: /home/joker/anaconda3/envs/conda_py27/lib/python2.7/site-packages. I additionally marked as resources (not sure if this is mandatory). Click ok and the reindexing happens. This solved the problem for me in PyCharm Professional 2016.2.3
Upvotes: 0
Reputation: 4423
The other reason may be project interpreter. For example, if you are using Python3.x, but the interpreter is for Python2.x You can check here:
File | Settings | Project: 'projectname' | Project Interpreter
Upvotes: 0
Reputation: 391
I did all the stuff above from einnocent and myildirim but still had to do the following:
close pycharm and manually delete the .idea folder, this deletes everything pycharm knows about the code.
open pycharm, reimport the project
the combination of setting the correct source root, restarting python with invaliding cache and deleting the .idea folder / reimporting the pycharm project fixed it for me.
Upvotes: 3
Reputation: 8985
I also had the problem, and it took me few hours to find the exact solution.
You need to confirm the following things.
'django.contrib.staticfiles'
, is added to INSTALLED_APPS
in the settings.py
file of your application.
The directory with the static contents (for example, images), named static
, resides under the application root.
PyCharm > Preferences > Project Settings > Django
Make sure your Django Project root
, Settings.py
and manage.py
script are well defined in the dialog box.
You are good to go. Hope this helps.
Upvotes: 5
Reputation: 3954
The key is to mark your source directory as a source root. Try the following:
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:
Upvotes: 126