0

I would like to run my python script as an executable from the command line, usually when I do a bash script I added this to the top of the file:

#!/bin/bash

Then I made the script executable with:

chmod u+x myScript.sh

Is there a way to do this in python scripting? I tried something similar like:

#!/bin/python

However, this did not work.

6
  • 1
    What is mkexec ? Did you mean to suggest chmod Commented Aug 2, 2018 at 19:04
  • 2
    Python is usually installed under /usr/bin/python Commented Aug 2, 2018 at 19:05
  • @Inian Whoops that is the alias I use alot, I will edit my question Commented Aug 2, 2018 at 19:06
  • 2
    I'd like to add to this question this excelent answer related to python and shebangs. Commented Aug 2, 2018 at 19:07
  • Thanks, @LucasWieloch. That's got much better info than the original dupe target, although that target's title matches this question better. Commented Aug 2, 2018 at 19:20

1 Answer 1

2

Add this to the top of your script

#!/usr/bin/env python

or

#!/usr/bin/env python3

depending if you want python2 or python 3

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.