Unresolved reference: 'django' error in PyCharm

37,729

Solution 1

I assume you're using a virtualenv which is located in the same directory as other project files. Python should know exactly that path. So, it's possibly that Pycharm is using the wrong Interpreter.

Go to Settings -> Project: -> Project Interpreter -> switch to the right path

In the interpreter packages, there should be Django package installed. If not, do it here/in terminal.

Solution 2

Mark root folder of project as 'Sources root', it works for me. Content Root

Solution 3

Above answers are answered partially.

Problem Description: I've multiple versions of python installed and Django is installed in one of Python version. There are two issues

  • Issue 1: Pycharm has wrong python interpreter. For this the Project Interpreter has to be changed to Python version where Django is installed. Solution: Follow all steps.

  • Issue 2: Django isn't listed as package. For this we need make available the installed python packages in the Pycharm environment. Solution: Follow all steps except step 3.

Solution: Peform following steps.

  1. In preference/settings go to Project > Project Interpreter
  2. On right hand side click on settings icon > Add Local
  3. Select correct Python version from Base Interpreter
  4. Mark the checkbox against Inherit global site-packages and Make available to all projects
  5. Click ok

Once this is done in Project Intepreter you will be able to see Django in the Package list.

Solution 4

If you create the project use python2.7, and in python2.7 path you installed the django, the project works normal. Then you switch the Project Interpreter to the python3.5, but this path did not install the django, then you will get this issue.

enter image description here

Solution 5

I got this problem and it stopped my unit tests from running.

I found that PyCharm, during an upgrade, had set my Python Interpreter to one which was in a virtual environment, which I do not use any more for this project. So I set it to my global Python environment in C:\Python and everything works like a charm.

I hope this will help someone.

Share:
37,729
m4jesticsun
Author by

m4jesticsun

Updated on September 04, 2020

Comments

  • m4jesticsun
    m4jesticsun almost 4 years

    I'm trying to import:

    from django.db import models
    

    PyCharm underlines django.db and complains: Unresolved reference 'django'.

    How do I get PyCharm to recognize Django?