Thursday, July 09, 2009

ImportError: No module named django.core (fun with Windows)

I just spent 45 minutes tracking this down, hopefully if I post a trace here, others will be able to resolve the issue more quickly in the future.

So I am building a little django app at work, but my latest installed version of django is pre-1.0, so why not upgrade, right?

After getting everything downloaded and running setup.py, I did the standard thing to start a new project:

C:\Users\jtb\Documents\Clickable\src>django-admin.py startproject myproject
Traceback (most recent call last):
File "C:\Python25\Scripts\django-admin.py", line 2, in
from django.core import management
ImportError: No module named django.core

All the search results on that error pointed to issues with my PYTHONPATH, but no amount of tinkering with it would make django actually run.

The real problem was that, due to a recent installation of Python 2.6, my PATH and my PYTHONPATH had fallen out of sync. My PATH was pointing to the Python 2.5 directories, while my PYTHONPATH was pointing to the 2.6 directories. It seems the Python installer I used knows how to update PYTHONPATH but not PATH. Which makes sense.

If you found this post through a web search and it helped you debug a similar issue, please post a comment.

2 comments:

Darth said...
This comment has been removed by the author.
Darth said...
This comment has been removed by the author.