How to run Python file from Mac Terminal

In order to run a Python (.py extension) file from the Mac Terminal all you need to do is type python3 followed by the name of the Python file.

  1. Open Mac Terminal,
  2. Type,
    python3 <file-name>
    % python3
    Hello World!
Run Python File using Mac Terminal

If you are using an older version of Python, then you may have to use python instead of python3

If Python is not installed on your Mac you will get an error,

% python3 
zsh: command not found: python3

Have Questions? Post them here!