windows7, django-admin.py, system variables, no module named django.core

561 views
Skip to first unread message

gintare

unread,
Aug 25, 2010, 4:06:07 AM8/25/10
to Django users
I am not able to run django under windows7

python django-admin.py #is recognized if i paste it to c:/first/
Python26 together with python executable.

I am getting error: No module named django.core
File "django-admin.py", line2, in <module>
from django.core import management

It seems the command line do not know about variables in the path:
Python django-admin.py #is not recognized if i use path variable
"C:/first/Python26/Lib/site-packages/django-1.2.1/django/bin"
It is recongmized as a command in if paste it to C:/first/Python26.

I added paths to System Path Variable:
C:/first/Python26
which contains copy af django-admin.py
C:/first/Python26/Scripts which
contains copy af django-admin.py
C:/first/Python26/Lib/site-packages/django-1.2.1/django/bin -
original django-admin.py

I run from command line cmd beeingin c:/first/Python26
python # command works

Sam Lai

unread,
Aug 25, 2010, 5:49:38 AM8/25/10
to django...@googlegroups.com
If you want to understand why you are getting the error, start by
understanding Python modules -
http://docs.python.org/tutorial/modules.html

Hint - you can't just copy a script around and expect it to work. The
script depends on other files to make it all happen.

If in python, you type,

import sys
sys.path

... and you see something like C:\first\Python26\Lib\site-packages, it
should work fine assuming Django was installed using setuptools or
pip. If not, you should look into using that instead of manually
installing it.

If you insist on doing it manually, you need to look into creating a
.pth file to add the packages into the PYTHONPATH.

> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to django-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>
>

gintare

unread,
Sep 3, 2010, 3:47:20 AM9/3/10
to Django users
Thanks a lot!
Would like to clearify how i should run python from command line:

1)
cmd
#in command line shell under windows
cd c:/first/Pyhton26
#change to directory with pyhton executable
python #
to start python environment in comman line shell
>>>>import sys
>>>>sys.path #prints C:\first\Python26\Lib\site-packages as one of paths
>>>>django-admin.py syncdb # ERROR - name 'django' is not defined


OR

2)
cmd
#in command line shell under windows
cd c:/first/Pyhton26
#change to directory with pyhton executable

pyhton django-admin.py syncdb #also ERROR: 'can
not open file django-admin.py'

pyhton django-admin syncdb #also ERROR: 'can
not open file django-admin'

django-admin.py syncdb #also ERROR: 'no module
named django.core'

django-admin syncdb #also ERROR: 'django-admin
is not recogmized as internal or external command'

The idea is that both "python executable" and "django/bin/ with
django-admin.py" are in system path.
Should i put only pyhton on systme path?

3)
I have several different pyhton installations. How cmd can recognize
python command if they all are under system path?
Does it first look in current working directory: I.e. if i start from
c:/fisrt/python26 it will not run python from c:/second/python31?






On Aug 25, 12:49 pm, Sam Lai <samuel....@gmail.com> wrote:
> If you want to understand why you are getting the error, start by
> understanding Python modules -http://docs.python.org/tutorial/modules.html
>
> Hint - you can't just copy a script around and expect it to work. The
> script depends on other files to make it all happen.
>
> If in python, you type,
>
> import sys
> sys.path
>
> ... and you see something like C:\first\Python26\Lib\site-packages, it
> should work fine assuming Django was installed using setuptools or
> pip. If not, you should look into using that instead of manually
> installing it.
>
> If you insist on doing it manually, you need to look into creating a
> .pth file to add the packages into the PYTHONPATH.
>
> On 25 August 2010 18:06,gintare<g.statk...@gmail.com> wrote:
>
>
>
> > I am not able to run django under windows7
>
> > python django-admin.py  #is recognized if i paste it to c:/first/
> > Python26 together with python executable.
>
> > I am getting error:  No module named django.core
> > File "django-admin.py", line2, in <module>
> > from django.core import management
>
> > It seems the command line do not know about variables in the path:
> > Python django-admin.py    #is not recognized if i use path variable
> >  "C:/first/Python26/Lib/site-packages/django-1.2.1/django/bin"
> > It is recongmized as a command in if paste it to C:/first/Python26.
>
> > I added paths to System Path Variable:
> > C:/first/Python26
> > which contains copy af django-admin.py
> > C:/first/Python26/Scripts                                      which
> > contains copy af django-admin.py
> > C:/first/Python26/Lib/site-packages/django-1.2.1/django/bin      -
> > original django-admin.py
>
> > I run from command line cmd beeingin c:/first/Python26
> > python  # command works
>
> > --
> > You received this message because you are subscribed to the Google Groups "Django users" group.
> > To post to this group, send email to django...@googlegroups.com.
> > To unsubscribe from this group, send email to django-users...@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.- Hide quoted text -
>
> - Show quoted text -

gintare

unread,
Sep 3, 2010, 5:42:52 AM9/3/10
to Django users
Hello,

I mean the correct way of running django seems to be to add to windows
environmental variable PATH c:/first/Python26/Lib/site-packages/
Django-1.2.1/django/bin
and when run
$ cmd
$ django-admin.py startproject mysite

the question, why importing management from django.core do not work?
from django.core import management
Error: No module django.core

the module is under c:/first/Python26/Lib/site-packages/Django-1.2.1/
django
I mean it seems cmd must know where are all django modules. How?

Sam Lai

unread,
Sep 4, 2010, 6:36:46 AM9/4/10
to django...@googlegroups.com

How did you install Django? In c:/first/Python26/Lib/site-packages, is
there a .pth file? If so, what is in it?

It sounds like you did not install Django properly - you just unpacked
it inside c:/first/Python26/Lib/site-packages. There's a bit more to
it. The best way to do it is to use the setup script provided with
Django (if you're doing this, do NOT unpack the archive inside
site-packages; the setup script will do the copying for you), or use
easy_install or pip (which you may have to install separately).

To use the provided setup script, simply unpack the Django tarball to
somewhere temporary. The open the command prompt at that location, and
type -

python setup.py install

And Python should do the rest. You should have a working Django setup
by the end.

Also, C:\first\Python26\Scripts should be in your Windows PATH, but
none of the other Python related paths. Python already knows about its
site-packages directory. And inside C:\first\Python26\Scripts, there
should be a file named django-admin.py once the above setup script has
finished.

Reply all
Reply to author
Forward
0 new messages