Setting Up Python: A Complete Guide for All Operating Systems

Python is one of the most popular and versatile programming languages, widely used in web development, data science, and automation. To get started with Python, you need to install it and set up an IDE (Integrated Development Environment). This guide will walk you through the steps to install Python and configure your environment on Windows, macOS, and Linux. It will also help you set up popular IDEs like VS Code, PyCharm, and Jupyter Notebook.

Installing Python

On Windows

  1. Download the Python Installer:

    • Visit the official Python website: python.org/downloads.
    • Choose the latest version for Windows (Python 3.x).
    • Click on the Download Python button.
  2. Run the Installer:

    • Once the installer is downloaded, run it.
    • Important: Check the box that says “Add Python to PATH” before clicking Install Now.
    • Follow the prompts and complete the installation.
  3. Verify the Installation:

    • Open Command Prompt (press Windows + R, then type cmd and press Enter).
    • Type python --version to verify the installation. You should see the Python version installed.
python --version

On macOS

  1. Install Python via Homebrew (Recommended):

    • First, ensure you have Homebrew installed. If not, open the Terminal and install it by running:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • Install Python using Homebrew by running:
brew install python

Verify the Installation:

  • Open the Terminal and type python3 --version to verify Python 3 is installed:
python3 --version
    • You can also use python3 to run Python on macOS.

On Linux

  1. Install Python via Package Manager:

    • Most Linux distributions come with Python pre-installed. To check if Python is installed, open the terminal and run:
python3 --version
  • If not installed, use the following commands to install Python:

  • Ubuntu/Debian-based:

sudo apt update
sudo apt install python3

Fedora:

sudo dnf install python3

CentOS:

sudo yum install python3

Verify the Installation:

  • Use the command python3 --version to verify that Python has been installed successfully.

Setting Up an IDE (VS Code, PyCharm, Jupyter Notebook)

On Windows, macOS, and Linux:

VS Code Setup
  1. Download and Install VS Code:

    • Visit the VS Code download page and choose the version for your operating system.
    • Download the installer and follow the prompts to install.
  2. Install the Python Extension:

    • Open VS Code, go to the Extensions view by clicking the Extensions icon on the left sidebar, and search for “Python.”
    • Click Install on the Python extension by Microsoft.
  3. Configure VS Code to Use Python:

    • Open the Command Palette (Ctrl + Shift + P or Cmd + Shift + P on macOS) and type Python: Select Interpreter.
    • Choose the Python interpreter from the list.
  4. Verify Installation:

    • Create a new Python file (.py) in VS Code and write a simple script:
    python
    print("Hello, Python!")
    • Run it using the green play button in the top right or by pressing Ctrl + Shift + P and selecting “Run Python File.”
PyCharm Setup
  1. Download and Install PyCharm:

  2. Configure Python Interpreter:

    • Once PyCharm is installed, open it and create a new project.
    • In the Project Interpreter section, select the Python version you installed earlier.
  3. Write and Run Code:

    • Create a new Python file in your project and write a script:
print("Hello, PyCharm!")
    • Run the script by right-clicking on the file and selecting Run.
Jupyter Notebook Setup
  1. Install Jupyter Notebook:

    • Open your terminal (or Command Prompt on Windows) and install Jupyter using pip:
pip install notebook

A new tab will open in your default browser. You can create a new Python notebook by selecting New > Python 3.

  • Write and Run Code in Jupyter:

    • Inside the notebook, you can write Python code and execute it in cells. For example:
print("Hello, Jupyter!")

Run the cell by pressing Shift + Enter.

Best Practices for Python Setup

  • Use Virtual Environments: Create a virtual environment for each project to manage dependencies separately.
 
python3 -m venv myenv

Activate the virtual environment:

      • Windows: myenv\Scripts\activate
      • macOS/Linux: source myenv/bin/activate
  • Keep Python and IDE Updated: Regularly check for updates for both Python and your IDE to take advantage of the latest features and bug fixes.

  • Organize Your Projects: Use proper folder structures for your Python projects. Keep source code, tests, and resources in separate directories.