


Now, the /usr/bin/env part means that we are calling env to find the python command from $PATH and execute it for us. The #! syntax is used mostly in scripts (where you need an interpreter). Add the following line to the first line of your Python script. The solution to overcome this is pretty simple. My shell (bash) thought that it was a bash script. The reason why we got this error is because by making hello.py an executable file, all we did was tell the shell that "You can execute it", but not what interpreter/program to use when it is being executed. What? Syntax error? But it is a valid Python program/script. hello.py: 1: Syntax error: word unexpected (expecting ")")

Right? I have a file hello.py, let's try running it. To make your Python script executable, run the following command in your terminal: chmod +x. If you might have noticed, the bash scripts that you can execute by simply typing out their relative/absolute path, they are "executable" files. In order to achieve this, a few things should be done first. sh like you do with Python scripts by typing python. You may have encountered executing bash scripts simply by typing out their relative/absolute path in the terminal. This will ensure that if the file's contents are valid, it will be executed without any problems. The easiest method to run a Python script on any Linux distribution is by invoking the python command and provide it with the name of your Python script. So if you want Python 3 to be guaranteed, use python3. Some distributions have used python2 as python and have an explicit command python3 for python3.
