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.

Example:
  1. Open Mac Terminal,
  2. Type,
    python3 <file-name>
    % python3 HelloWorld.py
    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 HelloWorld.py 
zsh: command not found: python3

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap