1

I am learning Python and DJango and I am relatively nub with Linux. When I create DJango project I have manage.py file which I can execute like ./manage.py runserver. However when I create some Python program by hand it looks like that my Linux trying to execute it using Bash, not Python. So i need to write python foo.py instead ./foo.py. Attributes of both files manage.py and foo.py are the same (-rwx--x---). So my Q is: where is difference and how I can execute python program without specifying python? Links to any documentations are very appreciate. Thanks.

levi
  • 19,165
  • 7
  • 56
  • 68
Abelisto
  • 12,110
  • 2
  • 24
  • 35

3 Answers3

5

You missed one step, after give the corrects permissions to the file, open your foo.py then put this on the first line

#!/usr/bin/env python

Then you can use ./foo.py

Abelisto
  • 12,110
  • 2
  • 24
  • 35
levi
  • 19,165
  • 7
  • 56
  • 68
1

I am just gonna add this for more clarity and to anyone coming across this post who might need an explanation.

Why do people write #!/usr/bin/env python on the first line of a Python script?

explains why you should it is used.

Community
  • 1
  • 1
pycod333
  • 673
  • 1
  • 6
  • 16
  • I needed an explanation and I already found it when @levi explain to me the direction of search. In any case thanks and +1 – Abelisto Nov 02 '15 at 08:57
-2

Save your python code file somewhere, using "Save" or "Save as" in your editor. Lets call it 'first.py' in some folder, like "pyscripts" that you make on your Desktop. Open a prompt (a Windows 'cmd' shell that is a text interface into the computer): start > run > "cmd".

Abhi
  • 1