yossi yossi - 2 years ago 375
Python Question

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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download