I am just starting to use terminal for my programming needs. In a lot of Django tutorials I see people say, for example, I should type this in terminal:
manage.py runserver
However when I do this it says:
bash: manage.py: command not found
I get it to work when I do: python manage.py runserver, however I would like to understand why this works and the other method doesn’t. I guess these are some very basic things but I thought I’d ask here.
bash(1)will search yourPATHenvironment variable to find programs to execute.PATHdoes not normally contain your “current working directory” (.) because that opens people up to trivial security problems:If
unsavory_characterplaces an executable in/home/unsavory_character/lsthat adds his or herssh(1)key to your~/.ssh/authorized_keysfile, you’d be in for a surprise — he or she could log in as you without a password.So systems these days don’t add the current working directory to the
PATH, because it is too unsafe.The workaround:
Of course, that assumes your current working directory is whichever directory contains the
manage.pyscript. That might be a safe assumption. If you’d like to be able to execute it from anywhere in the filesystem, you can add the directory to yourPATHby editing your~/.profileor~/.bash_profileor~/.bashrcfile. (If one of them already exists, pick that one. I seem to recall others withPATHproblems on OS X found one or the the other file worked well, and the other one never got executed.)(In my case, I have a bunch of self-written utilities in
~/bin/, but yours might be elsewhere. Change the paths as appropriate.)