Pycharm is not recognizing django, even though it is installed correctly. Why?

20,720

Solution 1

If you are using virtual environment, go

File > Settings > Project:PycharmProjects > Project Interpreter

and for the current project select the Python path inside your virtualenv at the select box. The path for your python will look similar to this:

~/PycharmProjects/your-project-path/venv/bin/python

Solution 2

I was facing similar issue. Pycharm was not showing and django options. To configure I did the following things:

  • go to edit configuration(run/debug menu)
  • In script path provide your manage.py location
  • in parameters provide 'runserver'
  • in python interpreter provide python location inside your virtual env

And now you can run and debug the django project using pycharm.

Solution 3

The django version in local might not be the same as to which is saved into virtual environment. In order to resolve this, it is necessary that interpretor in intellij should point to python file saved into virtual environment. In order to do this performa following actions:

  1. Move into project interpretor settings in Pycharm. (command + ',')
  2. In Project Interpretor option, give the path of python3 which is present inside bin directory inside your virtual env where project is located.
  3. Applying these changes should remove the errorenter image description here

  4. In the above pic, highlighted text shows where python binary file is present.

Solution 4

Only thing that I could thing to do to solve this, at least for now, was to go into Run/Debug Configurations and set the PYTHONPATH environment variable manually to include the site-packages directory where everything is installed. Once this was done, everything worked fine. Still no clue why this would be there in the terminal but not be set in Pycharm when I'm using the same venv for both. Nor does it make any sense to me why this seemed to happen all of a sudden. Very odd.

Solution 5

Just had the same problem, I went to External libraries -> interpreter ->site packages and "resyncronized" the forlder. django apperared. It seems to me it pycharm did notu update the project structure after I installed some packages.

Share:
20,720
meesterguyperson
Author by

meesterguyperson

Updated on July 09, 2022

Comments

  • meesterguyperson
    meesterguyperson almost 2 years

    I've got my project set up under a native virtual environment in 3.4 and have had it that way for a while and had it working fine. But for some reason, I am now having issues with running my project through Pycharm. Just to check that everything was set up properly, I did the following:

    >>> import sys
    >>> sys.path
    >>> import django
    

    I can confirm that PROJECT/lib/python3.4/site-packages is included in the path and that Django is installed in this path.

    However, when I attempt to run the project through Pycharm I get ImportError: No module named 'django'. I added the following to the Django's manage.py to troubleshoot:

    sys.stdout.write(', '.join(sys.path))
    

    The site-packages directory is nowhere to be found. Next, I went to "Settings > Project Interpreter" to make sure I had the correct interpreter chosen. It lists Python 3.4 under the virtual environment and includes Django as the first of the installed packages.

    My question, what the heck, Pycharm? The virtual environment is clearly set up correctly. The path is correct from the python terminal and Pycharm itself recognizes all the packages from the virtual environment under it's project interpreter section. Why then, when I actually run the project, does Pycharm stupidly decide to forget to run the project using the virtual environment and not use the correct python path? Little frustrated here. Would appreciate any suggestions.

  • meesterguyperson
    meesterguyperson almost 9 years
    As I mentioned in the description, I did this, and it is.
  • suselrd
    suselrd almost 9 years
    I dont mean Settings-->Project Interpreter, but Run-->Edit configurations
  • Daniel Schaffer
    Daniel Schaffer over 4 years
    This is what worked for me - I was not able to make the server work with the "Django" configuration, I had to use a "Python" configuration.