Getting started with Python on a Mac with an M1 chip is a straightforward process. Below, I'll guide you through the steps to set up Python, create a simple "Hello, World!" program, and run it to see the output.
macOS comes with Python pre-installed, but it's usually Python 2.7. Since you'll want to use Python 3, you should first check if it's already installed:
- Open the Terminal app (you can find it using Spotlight search by pressing
Cmd + Space
and typing "Terminal"). - Type
python3 --version
and pressEnter
. If you see a version number (e.g., Python 3.x.x), Python 3 is installed. If not, you'll need to install it.
If Python 3 is not installed:
- Visit the official Python website and download the latest Python 3 installer for macOS.
- Open the downloaded
.pkg
file and follow the installation instructions.
-
Open a text editor (TextEdit, VS Code, Atom, etc.).
-
Type the following Python code:
print("Hello, World!")
-
Save the file on your Desktop (or any preferred location) with a
.py
extension, for example,hello.py
.
- Return to the Terminal app.
- Change the directory to where your Python script is saved. If you saved it on the Desktop, you would use:
cd Desktop
- Run the script by typing:
python3 hello.py
- Press
Enter
. You should see "Hello, World!" printed in the Terminal.
After running the python3 hello.py
command, the Terminal will execute your Python script, and you should see the output directly below your command, displaying the text:
Hello, World!
- Code Editor: For a better coding experience, consider using a dedicated code editor like Visual Studio Code or PyCharm. These editors offer syntax highlighting, code completion, and other features helpful for writing Python code.
- Learning Resources: To learn more about Python programming, consider visiting the official Python documentation or resources like Codecademy and Kaggle for interactive learning.
- Managing Python Versions: As you progress with Python, you might need to work with multiple projects requiring different Python versions. Tools like
pyenv
can help manage multiple Python versions on the same system.
By following these steps, you've successfully run a simple Python program on your Mac with an M1 chip. Happy coding!