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
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
--
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.
Try
ftype py_auto_file
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
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
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
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
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
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.
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
What's with the spelling error?
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