Python Tutorial for Beginners 1: Install and Setup for Mac and Windows

3 min read 1 hour ago
Published on Nov 06, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

This tutorial will guide you through the installation and setup of Python on both Mac and Windows operating systems. By the end of this guide, you'll have a working Python environment and be ready to write your first script.

Step 1: Install Python on Mac

  1. Download Python

    • Visit the official Python website: python.org
    • Click on the "Download Python" button for the latest version.
  2. Run the Installer

    • Open the downloaded .pkg file.
    • Follow the installation prompts. Make sure to check the box that says "Add Python to PATH" during installation.
  3. Verify the Installation

    • Open the Terminal.
    • Type python3 --version and press Enter. You should see the installed Python version.
  4. Install Pip (if not included)

    • Pip is a package manager for Python. To check if it’s installed, type pip3 --version in Terminal.
    • If not installed, run:
      sudo easy_install pip
      

Step 2: Install Python on Windows

  1. Download Python

    • Go to the official Python website: python.org
    • Click on the "Download Python" button for the latest version.
  2. Run the Installer

    • Open the downloaded .exe file.
    • Ensure you check the box that says “Add Python to PATH” before clicking “Install Now.”
  3. Verify the Installation

    • Open Command Prompt.
    • Type python --version and press Enter. You should see the installed Python version.
  4. Install Pip (if not included)

    • Pip usually comes with Python installations. To check, type pip --version in Command Prompt.
    • If it's not installed, download get-pip.py from the official site and run:
      python get-pip.py
      

Step 3: Setting Up a Code Editor

  1. Choose a Code Editor

    • Options include Sublime Text, Atom, or any preferred IDE.
    • For Sublime Text, download it from sublimetext.com and install it.
  2. Configure the Editor

    • Open Sublime Text or your chosen editor.
    • Create a new file and save it with a .py extension to indicate it's a Python script.

Step 4: Create and Run Your First Python Script

  1. Write a Simple Script

    • Open your code editor and create a new file named hello.py.
    • Add the following code:
      print("Hello, World!")
      
  2. Run Your Script

    • On Mac: Open Terminal, navigate to the script's directory using cd command, and run:
      python3 hello.py
      
    • On Windows: Open Command Prompt, navigate to the script's directory, and run:
      python hello.py
      
  3. Check Output

    • You should see "Hello, World!" printed in the terminal or command prompt.

Conclusion

You have successfully installed Python on both Mac and Windows, set up a code editor, and run your first Python script. From here, you can explore more advanced Python tutorials and begin developing your programming skills. Consider checking out the full Python Beginner Series for more comprehensive learning. Happy coding!