How can I get IntelliJ IDEA to recognize common Python modules? IntelliJ IDEA is complaining "unresolved reference" on everything despite that I have added my virtual environment as a "Python interpreter" and invalidated caches. These (1)(2) related questions did not help resolve the issue.
-
check whether it helps https://stackoverflow.com/questions/21236824/unresolved-reference-issue-in-pycharm – Haifeng Zhang Mar 06 '18 at 22:19
-
I marked my root folder as "sources", but I couldn't find any place where I could check a box that says "add source roots to pythonpath". – Atte Juvonen Mar 06 '18 at 22:25
-
2Have you tried to run "File | Invallidate Caches"? – y.bedrov Mar 08 '18 at 05:54
-
Yes. (this text exists to fill minimum comment length) – Atte Juvonen Mar 08 '18 at 15:08
-
@AtteJuvonen , Could you fix the issue? I've been trying to fix it for a couple of days. – ipeluffo Apr 10 '18 at 09:38
-
No, I moved from IDEA to PyCharm because of this. Good luck! – Atte Juvonen Apr 10 '18 at 15:54
-
@AtteJuvonen , today a new version of IntelliJ and Python plugin were released and they fixed the issue to me. Just give a try – ipeluffo Apr 11 '18 at 09:22
-
@y.bedrov I did and it worked for a while but at some point the problem reappeared – Alvin May 09 '18 at 15:44
3 Answers
The errors are caused by wrong source roots configuration. Your project doesn't know where to locate the reference.
Add a new content root From the main menu, select File | Project Structure⌘; and click Project Settings | Modules.
Select the necessary module and then open the Sources tab in the right-hand part of the dialog.
Click Add Content Root and specify the folder that you want to add as a new content root.
The link is here.
IntelliJ support discussed the same issue at here.
Another stack overflow discussion is here.

- 1,687
- 2
- 19
- 36
you can try this :
Project Structure -> SDKs -> "+" -> Python SDK
Project -> Project SDK -> Python 2.7.10 #Choose the python version that you want

- 98
- 11
-
-
-
-
Solved it for me, seems like a restart of the IDE was necessary before the changes took effect. – Paul M. May 19 '23 at 14:22
This fixed for me when I setup the Python interpreter again. Apparently the problem was that the Python SDK's classpath was empty.

- 71
- 1
- 2