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
  • 22,001
  • 7
  • 73
  • 74
Abelisto
  • 14,826
  • 2
  • 33
  • 41

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
  • 14,826
  • 2
  • 33
  • 41
levi
  • 22,001
  • 7
  • 73
  • 74
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
  • 764
  • 2
  • 7
  • 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
  • OP OS is linux not window. – levi Nov 02 '15 at 06:18
  • I am not such nub to saving anything to the folder on the Windows desktop *~<;o) Yes you are really missed `linux` in the question tags (I does not downvote your answer if any, thanks for try and have fun) – Abelisto Nov 02 '15 at 07:27