I want run this simple python code int terminal:
#! /usr/bin/env python3
print('Hello world')
I saved this script as hello.py
I go to terminal to write down:
$ chmod +x hello.py
then I click enter. This is to allow permission to be granted. Terminal then showed me this:
-bash: $: command not found
Ok...I then write down the path to hello.py:
$ /Users/myname/Documents/MyPythonScripts/hello.py
I press enter. I was expecting terminal to print out hello world but to my horror, terminal show this:
/Users/myname/Documents/MyPythonScript/hello.py: line 3: syntax error near unexpected token `'Hello world''
/Users/hadi/Documents/MyPythonScript/hello.py: line 3: `print('Hello world')'
What's wrong here?
Btw, Running on macOS 10.13.3 and Python 3.6.3
$sign at the start of the line? If you saw it in examples, it is only the prompt, it's not part of the command. So simply enterchmod +x hello.py#!) isn't recognized. It could happen if your line endings are not Unix '\n', but Windows line endings. What editor did you create your script with?chmod +x hello.py.#!/usr/bin/env python. Sorry to waste your time.