Pycharm error Django is not importable in this environment
Solution 1
I finally found the error. The problem was that one folder name in the virtualenv path had an accent.
This is the old path:
/Users/plorenzo/../telefónica/gestorSchools/venv
This is the new one that works:
/Users/plorenzo/../telefonica/gestorSchools/venv
Solution 2
Yet another case, where my virtualenv did have Django installed, but Pycharm would still display this error.
I eventually found out that the same virtualenv path had been duplicated in the list of available interpreters. Removing all of them and re-adding fixed it.
The duplication happened after I copied the .idea from another machine, and re-created the virtualenv from Pycharm although it was already listed as a (broken) interpreter.
Solution 3
In my case I had to go to Settings (Alt+F7, or the Spanner/Cog icon) and select a Python interpreter which has Django installed alongside it.
If Django isn't already installed, you should be able to install it via the + (plus) icon (not shown below) once an interpreter has been selected.
Solution 4
For people having selected a virtualenv/interpreter that HAS Django installed (but it might have changed python version since first selection...), and even re-installed Django, and still get this message, and slowly getting crazy:
File > Invalidate Caches / Restart ...
Also, keeping the list of available interpreters clean and correct always helps (on my linux, old interpreters of previous linux installations kept popping up...whaat), as well as not using special characters in virtualenv names (as was the OPs problem...see his answer).
Solution 5
Project interpreter, which is being used in the pycharm
setting , doesn't have the django
package installed. So go to
setting->Project->project interpreter
Then install django
package
it will work :)
![Pablo L](https://i.stack.imgur.com/y9q6q.jpg?s=256&g=1)
Pablo L
Updated on July 05, 2022Comments
-
Pablo L almost 2 years
I'm getting the following errors in Pycharm.
Error: Django is not importable in this environment
It used to work well but I moved the project and virtualenv to other directory and the error appeared. It's weird because if I run the project ignoring the configuration settings warning that I get, works fine.
The problem is that now, Pycharm is not finding the project interperter.
The command that Pycharm is running is:
/Users/plorenzo/../gestorSchools/venv/bin/python3.4 /Users/plorenzo/../gestorSchools/schoolsManager/manage.py runserver 8000
The virtualenv is activated.
My $PATH is:
/Users/plorenzo/../gestorSchools/venv/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
and my $PYTHONPATH:
/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4
I spent a few days trying to find the solution but I couldn't find it.
-
SaintWacko almost 6 yearsThank you! This is what was causing the issue for me, too
-
cwhisperer over 5 yearsin setting->Project->project interpreter I saw the Django package, but installing it again solved the problem for me
-
Nic Scozzaro about 5 yearsThank you. Just restarting PyCharm solved the issue for me.
-
stephendwolff about 5 yearsI had to remove the .idea folder, but didn't see the same virtualenv path, so not sure why i kept getting this.
-
Arnaud P about 5 yearsAfter a quick experiment: when opening the interpreter settings from inside a freshly created project, Pycharm still suggests the virtualenvs from my other projects. So I am tempted to conclude that the 'interpreter' data is stored somewhere more central. Eg. on linux I've got stuff in
~/.PyCharm2019.1
. Although this somewhat contradicts my own answer :p -
geekandglitter about 5 yearsRestarting Pycharm makes sense. What just now worked for me was uninstalling and reinstalling Django.
-
benzkji almost 5 yearsfun fact: you get all the upvotes, for a problem that was not yours, but that many others have!
-
maciek over 4 yearsSolved it for me, PyCharm 2019.3.1 (Professional Edition) Build #PY-193.5662.61, built on December 18, 2019
-
Troy over 4 yearsWow, I tried all 15 suggestions above here with no success, but this one finally worked!
-
Shane about 4 yearsSaved me a lot of head scratching just now, thank you!
-
CoderGuy123 about 4 yearsWorked for me too, was driving me nuts with a false positive error.
PyCharm 2016.3.2 Build #PY-163.10154.50, built on December 28, 2016
-
Iñigo González almost 4 yearsThis problem is really hard to spot if spanish is your native tongue.
-
Ivan Rostovsky over 3 yearsThanks! Exact my issue after I recreated the virtual env for the new version of python but with the same name as was before.
-
MikeSchem almost 3 yearsWork for me while using a docker image.
PyCharm 2020.3.3 (Professional Edition) Build #PY-203.7148.72
-
Admin over 2 yearsYour answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
-
benzkji over 2 yearslooks like this issue is still experienced in...2021...