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?
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?
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.
Mark root folder of project as 'Sources root', it works for me. Content Root
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.
Project
> Project Interpreter
settings icon
> Add Local
Base Interpreter
Inherit global site-packages
and Make available to all projects
ok
Once this is done in Project Intepreter
you will be able to see Django
in the Package list.
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.
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.
if you have installed Django successfully before, in a different location from project location:
in pycharm go to the setting
>Project
>project interpreter
.
right side of the Project Interpreter, click on setting icon and choose add local
.
then in New Environment check these two checkbox:
then press Ok
and Apply
button and wait installing the interpreter to your project location.
You can make pyCharm recognize it by setting it to use your virtualenv setup that I assume you had it already for the project
STEP 1: open preferences PyCharm > Preferences
STEP 2: Search for interpreter
and on the right window, select your virtual environment to be used in Project Interpreter
STEP 3 (ADDITIONAL): adding your environment to the list if it didn't show up
select show all interpreter, and then on the pop up window, click + icon on the bottom left
select radio button Existing Environment
and select your virtual env, and then check "Make available for all project" if you use the env for other project, and click ok
STEP 4: On the preferences window, click apply or straight click the ok button. wait couple second and django variable should be available in your project
Add this site-packages works for me. (On 20191218, using the newest version of PyCharm ,and python3.7.5 )
I had this problem too. In fact, I faced with this problem because django
package had not been installed in Pycharm. Therefore, I went to this path and clicked on plus sign;then, I searched django
and installed it. It worked well.
file
>setting
>project
>project interpreter
I used virtualenv in my project and the following steps is works for me.
Settings -> Project:XXX -> Project Interpreter --> click the right side icon next to project interpreter -> more -> select the virtualenv interpreter
hope it can help someone
I fix this issue by changing "Project Structure". Try to unmark parent folder as "Sources"