Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import Error: No module named django

I am using centos linux.

I had python 2.6 with django and now i upgraded to python 2.7.
Python 2.6 is located in /usr/lib/python2.6.
Python 2.7 is located in /usr/local/lib/python2.7.
They both have site-packages directory and they both contain django 1.2.

If i run python i get the 2.7 version.
My problem is that if try to import django i get

ImportError: No module named django

I am not sure where is my PYTHONPATH defined and if this is what i need to change. anyone ?

i ended up making a symbolic link to the 2.6 site-packages directory.

like image 721
yossi Avatar asked Feb 27 '12 08:02

yossi


People also ask

How do I fix django error module not found?

To solve the error, install the module by running the pip install Django command. Open your terminal in your project's root directory and install the Django module. Copied! After you install the Django package, you should be able to import it and use it.

How do I install django?

Django can be installed easily using pip . In the command prompt, execute the following command: pip install django . This will download and install Django. After the installation has completed, you can verify your Django installation by executing django-admin --version in the command prompt.

How do I know if django is installed?

Simply type python -m django --version or type pip freeze to see all the versions of installed modules including Django.

How do I fix ModuleNotFoundError No module named environ?

The Python "ModuleNotFoundError: No module named 'environ'" occurs when we forget to install the django-environ module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install django-environ command.


2 Answers

I had the same error, and this fix my issue

python -m pip install django

:) Done!

like image 120
accimeesterlin Avatar answered Sep 22 '22 02:09

accimeesterlin


To check your path, you can use the following code:

import sys      print(sys.path) 

If you already know where django is installed, it should be easy to test if the desired directory is in your path with directory in sys.path.

Regarding where your PYTHONPATH is defined, note that it's an environment variable, so you can check its value (if defined) with: echo $PYTHONPATH

like image 31
jcollado Avatar answered Sep 24 '22 02:09

jcollado