Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make python script executable on osx?

I just want to make my script as an application. double-click and run instead of running in terminal. I have done it before with automator but now, on el capitan it doesn't work. It only gives error without explanation.

When I try with automator I get this error:

"The action “Run Shell Script” encountered an error."

Also I tried the trick below, still I am not able to do this.

#!/usr/bin/env python

chmod +x script.py

SOLVED:

After these two steps. I changed "Open with" to terminal for only this file and changed the #!/usr/bin/env python , it works. But it doesn't work without the two steps below, you need to follow all steps.

Add #!/usr/local/bin/python in the beginning of the code. Then run chmod +x myscript.py in terminal. After that change the application open with to Terminal.

It worked for me.

like image 860
hzleonardo Avatar asked Jun 15 '26 01:06

hzleonardo


1 Answers

I have changed the mode by

sudo chmod +x file-name.py

Then Added the following line on top of the file-name.py

#!/usr/bin/env python

Then run the file by running ./file-name.py command and it works fine.

like image 78
Akhter-uz-zaman Avatar answered Jun 17 '26 20:06

Akhter-uz-zaman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!