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.

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

Comments

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.

1 Comment

I needed an explanation and I already found it when @levi explain to me the direction of search. In any case thanks and +1
-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".

2 Comments

OP OS is linux not window.
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)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.