Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pycharm error Django is not importable in this environment

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.

like image 682
Pablo Lorenzo Avatar asked Dec 08 '14 17:12

Pablo Lorenzo


People also ask

How do I enable Django in PyCharm?

To enable Django support, follow these steps: Open the project Settings/Preferences dialog ( Ctrl+Alt+S ) and navigate to the Languages & Frameworks | Django page. Make sure that the checkbox Enable Django support is selected. Apply changes (if any) and close the dialog.

Do I have to install Django for every project in PyCharm?

If you are using virtual environment for every new project then you need to install django each time. Other wise you can use single virtual environment for all the project.

Can I install Django in PyCharm Community Edition?

If you look at the features edition comparison matrix, you will see that only PyCharm Professional supports the Django Framework. You can set up a project from the command line using the manage.py script and just open it in PyCharm.


4 Answers

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.

like image 108
Arnaud P Avatar answered Oct 13 '22 01:10

Arnaud P


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.

enter image description here

like image 37
James Bradbury Avatar answered Oct 13 '22 02:10

James Bradbury


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). Messing with the .idea folder also is not recommended (dont copy it to your new computer ;-).

like image 31
benzkji Avatar answered Oct 13 '22 01:10

benzkji


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 :)

like image 16
Siyaram Malav Avatar answered Oct 13 '22 00:10

Siyaram Malav