deepng
deepng

Reputation: 819

Make HelloWorld python script executable

I am trying to make a python script executable. The script is an testHelloWorld.py

#!/usr/bin/env python
print 'Hello World'

I have made it executable by running

chmod +x testHelloWorld.py

$ python testHelloWorld.py prints "Hello World". But $ ./testHelloWorld.py doesn't do anything. What am I missing here? I am using a Mac Os X device and its running Python 2.7.5.

I have gone through the answers for earlier questions and have checked for mistakes, but still no luck. This is one such similar post - how to make python script self-executable

Upvotes: 6

Views: 9269

Answers (3)

effo
effo

Reputation: 1

On OS X, try to replace ".py" extension by ".command" ! I don't remember why but it works for me.

Upvotes: -1

Guiloga
Guiloga

Reputation: 1

Yo need to find where is located the python interpreter. Write:

which python

For me python interpreter is located at /usr/local/bin/python. So the hedaer on the python file should be that one (for me).

#!/usr/local/bin/python

After that change and making executable a python file by (chmod +x filename.py) you will be able to execute a python file by writing:

./filename.py

Upvotes: 0

brechmos
brechmos

Reputation: 1316

On my mac:

#! /usr/bin/python
print 'Hello world'

Then

chmod +x <filename>.py

and finally

$ ./<filename>.py

gives me...

Hello world

So it is just the first line. Change to #! /usr/bin/python

Upvotes: 7

Related Questions