Skip to content

Instantly share code, notes, and snippets.

@rupeshtiwari
Created March 7, 2024 21:53
Show Gist options
  • Save rupeshtiwari/afb54181b14ac1059fb33fe1cd240c76 to your computer and use it in GitHub Desktop.
Save rupeshtiwari/afb54181b14ac1059fb33fe1cd240c76 to your computer and use it in GitHub Desktop.
getting started with python

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.

Step 1: Check Python Installation

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:

  1. Open the Terminal app (you can find it using Spotlight search by pressing Cmd + Space and typing "Terminal").
  2. Type python3 --version and press Enter. If you see a version number (e.g., Python 3.x.x), Python 3 is installed. If not, you'll need to install it.

Step 2: Install Python 3 (if necessary)

If Python 3 is not installed:

  1. Visit the official Python website and download the latest Python 3 installer for macOS.
  2. Open the downloaded .pkg file and follow the installation instructions.

Step 3: Create a Python Script

  1. Open a text editor (TextEdit, VS Code, Atom, etc.).

  2. Type the following Python code:

    print("Hello, World!")
  3. Save the file on your Desktop (or any preferred location) with a .py extension, for example, hello.py.

Step 4: Run Your Python Script

  1. Return to the Terminal app.
  2. Change the directory to where your Python script is saved. If you saved it on the Desktop, you would use:
    cd Desktop
  3. Run the script by typing:
    python3 hello.py
  4. Press Enter. You should see "Hello, World!" printed in the Terminal.

What to Expect:

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!

Additional Tips:

  • 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment