0

How do I run a python script with python 3.7 by using this syntax: ./main.py?

By default, it runs with python 2.7 and thus I'm forced to run the script with python3 ./main.py

I am on MacOS.

2
  • 3
    en.wikipedia.org/wiki/Shebang_(Unix) Commented Oct 25, 2018 at 20:47
  • Thanks, I'm not used to write languages like Python, I'm more a JavaScript guy and almost never see shebangs Commented Oct 25, 2018 at 20:50

1 Answer 1

3

You could place a shebang on the first line of the file to make it executable (by python3):

#!/usr/bin/env python3
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks ! As I said as a comment on my post, I'm not used to write languages that use shebangs, and never thought about that, that's a simple and good solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.