Hadi K.
Hadi K.

Reputation: 73

PyCharm 2018 Python Unresolved Reference 'django' VirtualEnv

I have the newest PyCharm version (2018) and the latest Django version (2.1) and Python (3.6)

When I want to import something in PyCharm from Django:

from django.urls import url

I get an error message under django stating: Unresolved reference 'django'

I created a virtual environment and I ran a project on it, the most famous one (polls) and it ran very well.

But now I noticed that I have this error, what is the solution?

Thank you in advance.

Upvotes: 2

Views: 3172

Answers (3)

timothepoznanski
timothepoznanski

Reputation: 1112

I had this problem but none of the answers above and in other posts worked. I use the right interpreter and Django is well installed (in a venv).

I restored default settings with File > Manage IDE settings and this corrected the error. I suppose the last update of PyCharm went wrong and this restarted everything well.

/!\ As @Vegas precised it in the comment, all configurations will disappear

Upvotes: 0

geekandglitter
geekandglitter

Reputation: 390

I had this problem specifically with a tutorial that uses an SRC folder. I learned that the SRC folder needs to be marked as a "sources root" in Pycharm. Once done, then the error flagging goes away.
Try Django Tutorial

Upvotes: 0

Nipun Thennakoon
Nipun Thennakoon

Reputation: 3734

The current virtual environment you are using does not have django installed in it. Installing it for the current environment or using a project interpreter which have django installed should resolve the issue.

1. Installing Django on your current virtual environment via pycharm settings.

  • Go to Settings > Project > Project Interpreter and click the green plus sign on the right hand side (install option).
  • Search for django in the search bar of the available packages dialog and select it.
  • Select the install package option at the bottom.

2. Installing Django on your current virtual environment via pycharm terminal.

  • Click on the pycharm terminal and install django using

    pip install Django
    

3. Changing the current project Interpreter.

  • Go to Settings > Project > Project Interpreter and click on the project interpreter drop down menu.

  • Choose a project interpreter which have django installed.

Upvotes: 4

Related Questions