Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make HelloWorld python script executable

Tags:

python

unix

macos

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

like image 397
deepng Avatar asked Jun 17 '14 14:06

deepng


1 Answers

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

like image 54
brechmos Avatar answered Oct 14 '22 21:10

brechmos