How can I execute a python script directly (without prefix by the python command) from bash?

I am just starting to use the terminal for my programming needs. In many Django tutorials, I see people say, for example, that I have to type this in the terminal:

manage.py runserver

However, when I do this, he says:

bash: manage.py: command not found

I make it work when I do: python manage.py runserverhowever I would like to understand why this works and the other does not. I think these are some very simple things, but I thought I would ask here.

+3
source share
4 answers

bash(1) PATH, . PATH " " (.), :

cd /home/unsavory_character/
ls

unsavory_character /home/unsavory_character/ls, ssh(1) ~/.ssh/authorized_keys, - , .

, PATH, .

:

./manage.py runserver

, , - , manage.py script. . , PATH, ~/.profile ~/.bash_profile ~/.bashrc. ( , . , PATH OS X, , .)

( ~/bin/, . .)

if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi
+4

, manage.py script.

manage.py ( /usr/bin/python):

#!/usr/bin/python

script:

chmod +x manage.py

script ./manage.py runserver.

: http://effbot.org/pyfaq/how-do-i-make-a-python-script-executable-on-unix.htm

+11

manage.py . : chmod +x manage.py

0

"script", : ( .)

tee -a ~/.profile <<EOF

if [ -d "/Library/Python/2.6/site-packages/django/bin" ] ; then
    PATH=/Library/Python/2.6/site-packages/django/bin:$PATH
fi
EOF

django-admin.py ? , manage.py ../bin. , . ;)

Also, did you get Django through easy_install? My script expects you to use Snow Leopard with the system version (Python 2.6).

0
source

All Articles