Command "python manage.py runserver" causes import error

1,637 views
Skip to first unread message

Ken

unread,
Oct 3, 2009, 4:19:34 PM10/3/09
to Django users
I'm setting up my first Django and my first project on a Windows XP
machine, following the Django tutorial part 1 (http://
docs.djangoproject.com/en/dev/intro/tutorial01/#intro-tutorial01).

I'm stuck at the point where it says to test the installation by
starting the Django development server with the command: "python
manage.py runserver".

When I do that, I get the error:

C:\django\portal>python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 2, in ?
from django.core.management import execute_manager
File "C:\python24\Lib\site-packages\Django-1.1\django\core\management
\__init__.py", line 3, in ?
from optparse import OptionParser, NO_DEFAULT
ImportError: No module named optparse

There is no optparse.py within the Django installation (at C:
\Python24\Lib\site-packages\Django-1.1\) but there is one in C:
\Python24\Lib\.

Why is the "import" is not finding it?

~ TIA
~ Ken

PS This is similar to another post in this forum, at
http://groups.google.com/group/django-users/browse_thread/thread/1959f1635c89d8b2/38464d1999e43303?lnk=gst&q=python+manage.py+runserver#38464d1999e43303.
But the advice given there doesn't seem to apply here.

Karen Tracey

unread,
Oct 3, 2009, 8:42:59 PM10/3/09
to django...@googlegroups.com
On Sat, Oct 3, 2009 at 4:19 PM, Ken <k...@sunward.org> wrote:
I'm setting up my first Django and my first project on a Windows XP
machine, following the Django tutorial part 1 (http://
docs.djangoproject.com/en/dev/intro/tutorial01/#intro-tutorial01).

I'm stuck at the point where it says to test the installation by
starting the Django development server with the command: "python
manage.py runserver".

When I do that, I get the error:

C:\django\portal>python manage.py runserver
Traceback (most recent call last):
 File "manage.py", line 2, in ?
   from django.core.management import execute_manager
 File "C:\python24\Lib\site-packages\Django-1.1\django\core\management
\__init__.py", line 3, in ?
   from optparse import OptionParser, NO_DEFAULT
ImportError: No module named optparse

There is no optparse.py within the Django installation (at C:
\Python24\Lib\site-packages\Django-1.1\) but there is one in C:
\Python24\Lib\.

Why is the "import" is not finding it?


That would seem to be some problem with your Python installation.  The Lib directory ought to automatically be on the Python path when you run python.  You can check this by checking sys.path from a Python shell, for example:

D:\tmp>\bin\Python2.4.4\python.exe
Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', 'C:\\WINNT\\system32\\python24.zip', 'D:\\tmp', 'D:\\bin\\Python2.4.4\\DLLs', 'D:\\bin\\Python2.4.4\\lib', 'D:\\bin\\Python2.4.4\\lib\\plat-win', 'D:\\bin\\Python2.4.4\\lib\\lib-tk', 'D:\\bin\\Python2.4.4', 'D:\\bin\\Python2.4.4\\lib\\site-packages']

>>> from optparse import OptionParser, NO_DEFAULT
>>> NO_DEFAULT
('NO', 'DEFAULT')
>>>

But if it's not there I'm not sure how you'd fix it (nor, if it is there but for some reason you still cannot import stuff that is located in it, would I know how to fix that). 

Is there some reason you are using Python 2.4?  Django does work with it but it is fairly old.  Since there seems to be something off with the install you have you might just try installing a more recent Python and see if things improve.

Karen

Ken

unread,
Oct 13, 2009, 3:01:47 PM10/13/09
to Django users
Thanks Karen for your reply, and sorry for the delay in my reply.

It did turn out to be a PYTHONPATH issue. I finally solved it by

1. making sure the XP PYTHONPATH system variable exists and includes
at least: C:\python26;C:\python26\Lib\site-packages\dd_django;C:
\Python26\Lib;C:\Python26;C:\python26\Scripts;, and

2. put %PYTHONPATH%; into the system PATH var.

These were done at Control Panel \ System \ Advanced tab \ Environment
Variables button \ system variables field.

~ Ken
Reply all
Reply to author
Forward
0 new messages