django-admin.py startproject will NOT work.

2,621 views
Skip to first unread message

Chris Kavanagh

unread,
Dec 29, 2011, 11:32:05 PM12/29/11
to Django users
Hi, I'm using WinXP, Python27, django 1.3.1.

When I try django-admin.py startproject mysite, I get a "Usage django-
admin.py subcommand [options] [args]" listing of commands instead of
starting the project in mysite folder. . .I've tried every workaround
I've found on Google & on this site. I've put C:\Python27\Lib\site-
packages\django\bin in my Env Variable Path, I've changed the registry
setting HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command
to PYDIR\\python.exe" "%1" %*. I've typed in the full path in the
command line (python django-admin.py startproject mysite) & nothing
works. And yes, I set it up using python setup.py install.

Any suggestions or other work arounds??? I'm at my wits end!!! Thanks
for any help.

Ramiro Morales

unread,
Dec 30, 2011, 8:10:38 AM12/30/11
to django...@googlegroups.com

The safest, OS-independent and interpreted language-independent way to
get a script like django-admin to run is to simple use:

path\to\the\interpreter\binary path\to\the\script

In your case it could be:

C:\python27\python C:\path\to\django-admin startproject foo

or, if you have C:\python27 in the PATH, simply:

python C:\path\to\django-admin startproject foo

This is particularly true and useful in platforms like Windows where
there is no robust/official way to associate a scripting language source
code file to signal the OS which interpreter binary should process and
execute it (like the #!/path/to/python line in Unix).

There are a handful of third party solution and tricks (like the ones
you tried) but from the number of times this topic appears in mailing
lists IMHO it is evident they only muddle the landscape and/or break
things.

Regards,

--
Ramiro Morales

Kev Dwyer

unread,
Dec 30, 2011, 9:42:27 AM12/30/11
to django...@googlegroups.com
Chris Kavanagh wrote:

Hello,

If you're seeing the usage message then python is able to find and execute
the django-admin.py script, but the script doesn't like the input that you
are providing.

Can you provide a paste of what you enter in the command prompt, and the
output that you receive?

Cheers,

Kev

Chris Kavanagh

unread,
Dec 30, 2011, 2:04:54 PM12/30/11
to Django users
Thanks for the reply, however it didn't work. I get the exact same
thing: "Usage: django-admin.py subcommand [options] [args]" with
options below for help.


Chris Kavanagh

unread,
Dec 30, 2011, 2:13:31 PM12/30/11
to Django users
Thanks for the help. . .I created a directory named "mysite" then
opened a command prompt from the "mysite" directory. In the prompt I
put "django-admin.py startproject mysite". The output i get is
lengthy, but here it is. . .

Usage: django-admin.py subcommand [options] [args]

Options:
-v VERBOSITY, --verbosity=VERBOSITY
Verbosity level; 0=minimal output, 1=normal
out
2=all output
--settings=SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't
provid
DJANGO_SETTINGS_MODULE environment variable
wil
used.
--pythonpath=PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Print traceback on exception
--version show program's version number and exit
-h, --help show this help message and exit

Type 'django-admin.py help <subcommand>' for help on a specific
subcomm

Available subcommands:
cleanup
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
flush
inspectdb
loaddata
makemessages
reset
runfcgi
runserver
shell
sql
sqlall
sqlclear
sqlcustom
sqlflush
sqlindexes
sqlinitialdata
sqlreset
sqlsequencereset
startapp
startproject
syncdb
test
testserver
validate


And that's it. Thanks again for the help. . .Cheers


Timothy Makobu

unread,
Dec 30, 2011, 3:43:03 PM12/30/11
to django...@googlegroups.com
Hi,

If you can, upload a screenshot of the command prompt with the commands entered here https://droplr.com and send us the link.



--
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.


Chris Kavanagh

unread,
Dec 30, 2011, 7:12:13 PM12/30/11
to Django users


On Dec 30, 3:43 pm, Timothy Makobu <makobu.mwambir...@gmail.com>
wrote:
> Hi,
>
> If you can, upload a screenshot of the command prompt with the commands
> entered herehttps://droplr.comand send us the link.
>
> Certainly, thanks.

https://droplr.com/images

>
>
>
>
>
>

Chris Kavanagh

unread,
Dec 30, 2011, 7:36:32 PM12/30/11
to Django users

On Dec 30, 3:43 pm, Timothy Makobu <makobu.mwambir...@gmail.com>
wrote:
> Hi,
>
> If you can, upload a screenshot of the command prompt with the commands
> entered herehttps://droplr.comand send us the link.
>
> I'm not sure you'll be able to see the screenshot at the link, it's very small. So, here's a copy/paste of it from my command prompt:




C:\Documents and Settings\mysite>django-admin.py startproject mysite
Usage: django-admin.py subcommand [options] [args]

Options:
-v VERBOSITY, --verbosity=VERBOSITY
Verbosity level; 0=minimal output, 1=normal
output,
2=all output
--settings=SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't
provided, the
DJANGO_SETTINGS_MODULE environment variable
will be
used.
--pythonpath=PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Print traceback on exception
--version show program's version number and exit
-h, --help show this help message and exit

Type 'django-admin.py help <subcommand>' for help on a specific
subcommand.

Chris Kavanagh

unread,
Dec 30, 2011, 8:44:01 PM12/30/11
to Django users


On Dec 30, 8:10 am, Ramiro Morales <cra...@gmail.com> wrote:
Thanks again for the help Ramiro. . .When you say "C:\path\to\django-
admin startproject foo", I'm not quite sure which path you're
referring to. Do you mean "C:\Python27\Lib\site-packages\django
\bin" ??? This is where the django-admin script is located (also
located in Python Scripts Folder). BTW, I have my Python Path set in
Environment Variables along with the path to where django-admin.py is
located " C:\Python27;C:\Python27\scripts;C:\Python27\Lib\site-packages
\django\bin"

So, if you could help a moron like me out, and tell me exactly which
path you're referring to when you say "C:\path\to\django-admin
startproject foo" I'll give it a try.
Message has been deleted

Chris Kavanagh

unread,
Dec 31, 2011, 10:56:00 AM12/31/11
to Django users


On Dec 31, 10:19 am, Dennis Lee Bieber <wlfr...@ix.netcom.com> wrote:
> On Fri, 30 Dec 2011 16:36:32 -0800 (PST), Chris Kavanagh
>
> <cka...@gmail.com> wrote:
> >> I'm not sure you'll be able to see the screenshot at the link, it's very small. So, here's a copy/paste of it from my command prompt:
>
> >C:\Documents and Settings\mysite>django-admin.py startproject mysite
>
>         Have you tried that while explicitly specifying the Python
> interpreter on the line?
>
>         I seem to recall that Windows has some problem passing command line
> arguments when the first item (the "program") isn't directly executable.
>
> http://stackoverflow.com/questions/2640971/windows-is-not-passing-com...http://stackoverflow.com/questions/7860872/run-python-scripts-from-wi...
>
> (or for the full google list;http://www.google.com/search?q=windows%20python%20command%20line%20ar...
> )
> --
>         Wulfraed                 Dennis Lee Bieber         AF6VN
>         wlfr...@ix.netcom.com    HTTP://wlfraed.home.netcom.com/


Thanks for the reply Dennis. . .Yeah, I have tried that, LOL. Several
different ways actually. From what I can tell, it seems to solve this
problem for MOST people, but NOT me, lol.

Chris Kavanagh

unread,
Dec 31, 2011, 11:40:26 AM12/31/11
to Django users
While looking for a solution, I found someone with a similar problem.
he thought there was a problem with the way Python Files are
associated. So I did what was suggested on the command line, using
"assoc.py" and ftype Python.File. What I got back is listed below. I
don't think this is right according to what the message said.
According to him, it should've returned ".py=Python.File" and
"Python.File="C:\Python25\python.exe" "%1" %*". . .Obviously mine was
different. Any suggestions???




C:\>assoc .py
.py=py_auto_file

C:\>ftype python.file
File type 'python.file' not found or no open command associated with
it.

Bart Nagel

unread,
Dec 31, 2011, 11:45:43 AM12/31/11
to Django users

Try
ftype py_auto_file

Timothy Makobu

unread,
Dec 31, 2011, 11:47:35 AM12/31/11
to django...@googlegroups.com
Hi,

File associations are fine i reckon, because django-admin is giving you the help message because for some reason it thinks you're giving it improper input

Bart Nagel

unread,
Dec 31, 2011, 11:58:47 AM12/31/11
to django...@googlegroups.com
At 2011-12-31 19:47:35 +0300, Timothy Makobu wrote:
> File associations are fine i reckon, because django-admin is giving you the
> help message because for some reason it thinks you're *giving it improper
> input*.

What about other Python programs? Do they have the same problem?

Put this next paragraph in a file and run it with different numbers of
arguments and see what happens.

import sys
print "%d arguments" % len(sys.argv)

Save it as args.py

Run
python args.py
python args.py arg1
python args.py arg1 arg2

Andre Terra

unread,
Dec 31, 2011, 12:13:26 PM12/31/11
to django...@googlegroups.com

Ramiro Morales

unread,
Dec 31, 2011, 12:38:10 PM12/31/11
to django...@googlegroups.com
On Fri, Dec 30, 2011 at 4:04 PM, Chris Kavanagh <cka...@gmail.com> wrote:
>>
>>   C:\python27\python C:\path\to\django-admin startproject foo
>>
>> or, if you have C:\python27 in the PATH, simply:
>>
>>   python C:\path\to\django-admin startproject foo
>>
>
> Thanks for the reply, however it didn't work. I get the exact same
> thing: "Usage: django-admin.py subcommand [options] [args]" with
> options below for help.
>

Try both, I think both of them should work.

BUT, that isn't the important part. The important part is abut you should
make sure you execute it with the Python interpreter.

Forget about trying to simple invoke django-admin (or django-admin.py)
as a standalone program.

Good luck.

--
Ramiro Morales

Chris Kavanagh

unread,
Dec 31, 2011, 5:53:40 PM12/31/11
to Django users


On Dec 31, 12:13 pm, Andre Terra <andrete...@gmail.com> wrote:
> This has been answered before:
>
> http://groups.google.com/group/django-users/browse_thread/thread/9d53...
>
> Cheers,
> AT
>
>
> Yes, I saw that thread, and I tried changing my registry as suggested. And the other 'work around'. Neither worked.
>
>
>
>

Chris Kavanagh

unread,
Dec 31, 2011, 5:56:19 PM12/31/11
to Django users


On Dec 31, 11:47 am, Timothy Makobu <makobu.mwambir...@gmail.com>
wrote:
> Hi,
>
> File associations are fine i reckon, because django-admin is giving you the
> help message because for some reason it thinks you're *giving it improper
> input*.
>
>So, you're saying you don't believe this is the problem (File Associations)?? I don't think it is either, but I thought it was worth a try. It was in a Stack Overflow question about Python (Windows) not accepting command line args.

Chris Kavanagh

unread,
Dec 31, 2011, 6:01:39 PM12/31/11
to Django users
As far as other programs, I'm not sure. I'm not a programmer (just
learned Python over the last few months) so I haven't tried any other
programs yet.

Ok, so save the paragraph in a file, then run the commands from the
command line EXACTLY as you have them? In other words, from command
line, type in Python args.py, then python args.py arg1, and python
args.py arg 2??

Forgive my ignorance, working from the command line with this stuff is
new to me. And I've never understood exactly what command line args
are. . .But I'm learning.

And THANK YOU ALL FOR THE HELP!!!

Chris Kavanagh

unread,
Dec 31, 2011, 6:10:51 PM12/31/11
to Django users
Thanks Ramiro. . .I don't think you saw my other reply to your
original post about trying this. . .

I'll ask again. I'm not sure exactly what path to use, when you say
\path\to. The directory I created is called "mysite" & it's path is C:
\mysite\.I started a command prompt from "mysite" then typed "python
django-admin.py startproject mysite" in the command prompt (didn't
work).

Forgive my ignorance, is this what you wanted me to try??

Bart Nagel

unread,
Dec 31, 2011, 6:18:13 PM12/31/11
to django...@googlegroups.com

The command line is the dream, you'll come to love it. Well, maybe not
the Windows one.

I guess first up just run
python
and see if you get the interactive Python shell. Or maybe you need
python.exe
since you're on Windows? Anyway, if you get the shell, the python
executable is in your path and works to at least some extent. If you
don't get the shell, and you get "command not found" or something (I
don't have a Windows box so I don't know exactly what it would look
like) you may need to use the full path to the executable, as people
before have suggested.

So those two lines ("import..." and "print...") make a very simple
Python script which just outputs the number of arguments it thinks it
was given.

Invoke the script with Python just as you're meant to do for the
Django script. On linux I just run
python args.py
and it tells me "1 arguments". If I run
python args.py something
it tells me "2 arguments" and so on.

What behaviour do you get?

The point of this is that if this python script can see the arguments
then I can see absolutely no reason why your django-admin.py script
would not see them, and I would be stumped.

--bart

Chris Kavanagh

unread,
Dec 31, 2011, 6:43:36 PM12/31/11
to Django users
Ok, I CAN start the Python Interpreter from the command line by just
typing "python" then "enter".

I saved the file "args.py" in the Python Scripts folder. When I try to
run it from command prompt, I get the message "python: can't open
file 'args.py': [Errno 2] No such file or directory".

The only way I CAN get it to open, is to change (cd into) into the
python scripts folder (where I saved args.py) then run it (type
"python args.py" in command prompt). So, obviously something is wrong.

Bart Nagel

unread,
Dec 31, 2011, 6:48:46 PM12/31/11
to django...@googlegroups.com
At 2011-12-31 15:43:36 -0800, Chris Kavanagh wrote:
> Ok, I CAN start the Python Interpreter from the command line by just
> typing "python" then "enter".
>
> I saved the file "args.py" in the Python Scripts folder. When I try to
> run it from command prompt, I get the message "python: can't open
> file 'args.py': [Errno 2] No such file or directory".
>
> The only way I CAN get it to open, is to change (cd into) into the
> python scripts folder (where I saved args.py) then run it (type
> "python args.py" in command prompt). So, obviously something is wrong.

No, that's not wrong, that's how it should be. The python interpreter
is in your path, but you're telling the interpreter which file to run.
If you tell it to run a file args.py and there is no such file in the
current directory, it's correct to give you an error message.

Does this little script tell you correctly the number of arguments you
pass to it?

--bart

Chris Kavanagh

unread,
Dec 31, 2011, 7:00:44 PM12/31/11
to Django users
Yes, it tells me the number of args.

BTW, thanks for the patience.

Chris Kavanagh

unread,
Dec 31, 2011, 7:01:31 PM12/31/11
to Django users

Bart Nagel

unread,
Dec 31, 2011, 7:13:01 PM12/31/11
to django...@googlegroups.com
> Yes, it tells me the number of args.

Okay, in that case the arguments should also be getting to the
django-admin script. To give you the help message it must not be able
to read the "startproject" argument, since the name of the project
shouldn't matter to it. Perhaps something bad is happening to it,
possibly due to the registry stuff you folks were talking about
earlier, or some other Windows sorcery.

Change args.py a little to this:

import sys
print "%d arguments: %s" % (len(sys.argv), sys.argv)

And now run it with the arguments you were trying to give to
django-admin:
python args.py startproject mysite

When I run that I get
3 arguments: ['args.py', 'startproject', 'mysite']

Paste your own output.

--bart

Chris Kavanagh

unread,
Dec 31, 2011, 9:47:13 PM12/31/11
to Django users
Forgive my ignorance, but if that's the way it's supposed to work
(script must be in current dir) then how would Python know to run
django-admin.py if I'm NOT in the same directory it is
(Python27\Scripts\)??? In other words, the tutorial says to create a
mysite dir somewhere, NOT in the Python27\Scripts dir. So how would it
work then if Python27\Scripts\ isn't my current working dir (ie:
mysite isn't in the Scripts dir)??

Chris Kavanagh

unread,
Dec 31, 2011, 9:56:14 PM12/31/11
to Django users

>
> No, that's not wrong, that's how it should be. The python interpreter
> is in your path, but you're telling the interpreter which file to run.
> If you tell it to run a file args.py and there is no such file in the
> current directory, it's correct to give you an error message.
>
> Does this little script tell you correctly the number of arguments you
> pass to it?
>
> --bart

Ok I've had a breakthrough (I guess,lol). I started a command prompt
from my Python Scripts folder (C:\Python27\Scripts\), typed in "Python
django-admin.py startproject mysite", and it worked!! I now have the
"mysite" folder with appropriate subfolders (__init__.py,
manage.py,settings.py,urls.py).

Is this working correctly?? Should I have to create Projects in the
Python Scripts Folder?? Should it work from another (any misc dir)
dir??

And, can I leave it in the Scripts Folder or should I move it?? If I
do move it, will that cause other problems??

Bart Nagel

unread,
Jan 1, 2012, 1:22:08 AM1/1/12
to django...@googlegroups.com
At 2011-12-31 18:47:13 -0800, Chris Kavanagh wrote:
> Forgive my ignorance, but if that's the way it's supposed to work
> (script must be in current dir) then how would Python know to run
> django-admin.py if I'm NOT in the same directory it is
> (Python27\Scripts\)??? In other words, the tutorial says to create a
> mysite dir somewhere, NOT in the Python27\Scripts dir. So how would it
> work then if Python27\Scripts\ isn't my current working dir (ie:
> mysite isn't in the Scripts dir)??

Three options:

Either you run
python C:\path\to\django-admin.py startproject mysite
from whatever directory you want, to run an arbitrary Python script
anywhere on your machine.

Or, with other scripts, from the directory where the Python script is,
you can generally do
python some-script.py C:\path\to\some\target
depending how the script itself is set up -- the django-admin.py
doesn't let you do this, it wants only to create a project in the
current directory.

Or (what you're encouraged to do in this case) the django-admin.py
script is set up somewhere in your lookup PATH. The lookup PATH is the
list of directories in which commands live, and so when asked to run a
particular command the shell looks in those directories and if it
finds the command you wanted runs it, no matter where you are. To get
the django-admin.py script in the PATH so you can run it from anywhere
without a full path either you install the script to a directory which
is already in your PATH (I think on Windows C:\windows\system32 is one
such directory) or the Django directory containing the script is added
to your PATH.

There might have been instructions to do that when you installed
Django, or perhaps it was done as part of an installation script.

The fact that this path exists is the reason you can run commands like
"python" itself from anywhere, if it's set up properly.

Bart Nagel

unread,
Jan 1, 2012, 1:49:16 AM1/1/12
to django...@googlegroups.com
At 2011-12-31 18:56:14 -0800, Chris Kavanagh wrote:
> Ok I've had a breakthrough (I guess,lol). I started a command prompt
> from my Python Scripts folder (C:\Python27\Scripts\), typed in "Python
> django-admin.py startproject mysite", and it worked!! I now have the
> "mysite" folder with appropriate subfolders (__init__.py,
> manage.py,settings.py,urls.py).

It still doesn't make sense that it wasn't working before. Did you try
the modified args.py script I sent you?

> Is this working correctly?? Should I have to create Projects in the
> Python Scripts Folder?? Should it work from another (any misc dir)
> dir??

If Python itself and the django-admin.py script were being found
properly (and they were when you were getting the help message), yes,
you should be able to do that from any directory.

> And, can I leave it in the Scripts Folder or should I move it?? If I
> do move it, will that cause other problems??

You should probably move it. It should work anywhere, again, as long
as it can find Python properly.

--bart

Timothy Makobu

unread,
Jan 1, 2012, 1:59:20 AM1/1/12
to django...@googlegroups.com
+1

Chris Kavanagh

unread,
Jan 1, 2012, 4:12:27 AM1/1/12
to Django users
I get the same as you:

C:\Python27\Scripts>python args.py startproject mysite
3 arguements: ['args.py', 'startproject', 'mysite']

Bart Nagel

unread,
Jan 1, 2012, 4:44:31 AM1/1/12
to django...@googlegroups.com
At 2012-01-01 01:12:27 -0800, Chris Kavanagh wrote:
> On Dec 31 2011, 7:13�pm, Bart Nagel <b...@tremby.net> wrote:
> > When I run that I get
> > � � 3 arguments: ['args.py', 'startproject', 'mysite']
> >
> > Paste your own output.
>
> I get the same as you:
>
> C:\Python27\Scripts>python args.py startproject mysite
> 3 arguements: ['args.py', 'startproject', 'mysite']

What's with the spelling error?

Chris Kavanagh

unread,
Jan 1, 2012, 5:23:50 PM1/1/12
to Django users
LOL, well apparently I don't know how to spell 'argument'.

However, I still got the same output as you (except for correct
spelling).

What exactly were we (you) looking for in this test??

Bart Nagel

unread,
Jan 1, 2012, 8:29:44 PM1/1/12
to django...@googlegroups.com

I explained that in a previous post. Afraid I can't help you any
further, though I'm glad you eventually got it working.

--bart

Andre Terra

unread,
Jan 2, 2012, 4:59:28 AM1/2/12
to django...@googlegroups.com
Use virtualenv:  http://pypi.python.org/pypi/virtualenv 


Cheers,
AT

Chris Kavanagh

unread,
Jan 2, 2012, 1:47:50 PM1/2/12
to Django users


On Jan 2, 4:59 am, Andre Terra <andrete...@gmail.com> wrote:
> Use virtualenv:  http://pypi.python.org/pypi/virtualenv
>
> Cheers,
> AT
>
> I think I'll give that a try. Thanks for the help.
>
>

Chris Kavanagh

unread,
Jan 2, 2012, 1:50:42 PM1/2/12
to Django users


Thanks to EVERYONE for the help! ( and Bart for his help/patience!)
Reply all
Reply to author
Forward
0 new messages