Alex
Alex

Reputation: 943

importerror: No module named django

I installed python 2.6 alongside my mac's 2.5.2 version. As soon as I did, python2.6 manage.py runserver failed because it couldn't find django.core.management.

From a shell, import django returns importerror: No module named django.

Why?

Upvotes: 6

Views: 17377

Answers (4)

Chris
Chris

Reputation: 7298

I use Bitnami's Django installer, and this happened for me when I wasn't in their custom shell, which I believe sets related python path environment variables. I ran ./use_djangostack in the root of the Bitnami package and then was successful running the server again.

Upvotes: 0

Jerome Jaglale
Jerome Jaglale

Reputation: 1873

Add site-packages to PYTHONPATH:

export PYTHONPATH="/home/jerome/bin/django-1.1/lib/python2.6/site-packages:$PYTHONPATH"

Worked on Ubuntu, with a python/django virtual environment using virtualenv and pip.

Source: http://benfsayer.com/importerror-no-module-named-django-core-management/

Upvotes: 0

Daniel Roseman
Daniel Roseman

Reputation: 600059

Because each installation of Python uses its own directory to store libraries. On a Mac, they are in /Library/Python/2.x/site-packages/. Presumably you originally installed Django in the 2.5 directory, but it isn't yet in the 2.6 one. You can symlink it there if you want to, or reinstall it using the new version.

Upvotes: 2

Esteban Küber
Esteban Küber

Reputation: 36862

Did you reinstall Django?

This happens when I install side by side versions of Python on Gentoo. Whenever I install a new version, I have to either reinstall the new ones or make a symlink to the old site-packages.

Upvotes: 3

Related Questions