Skip to content

Setting Up Python on Windows/Linux

Introduction

Python is a powerful, versatile programming language that's widely used for various applications, from web development to data science. This guide will help you set up Python on both Windows and Linux systems.

Setting Up Python on Windows

Step 1: Download Python Installer

  1. Go to the official Python website.
  2. Click on the Downloads section.
  3. Download the latest Python installer for Windows.

Step 2: Run the Installer

  1. Open the downloaded installer.
  2. Check the box that says "Add Python to PATH". This is crucial for running Python from the command line.
  3. Click on "Install Now".
  4. Once the installation is complete, click "Close".

Step 3: Verify the Installation

  1. Open Command Prompt.
  2. Type python --version and press Enter. You should see the installed Python version.
  3. Similarly, type pip --version to verify that pip (Python's package installer) is also installed.

Step 4: Install a Code Editor (Optional)

  1. Download and install a code editor like Visual Studio Code or PyCharm.

Setting Up Python on Linux

Step 1: Update Package List

Open a terminal and run the following command to update your package list:

sudo apt update

Step 2: Install Python

Most Linux distributions come with Python pre-installed. To check if Python is installed, run:

python3 --version

If Python is not installed, you can install it using:

sudo apt install python3

Step 3: Verify the Installation

To verify the installation, run:

python3 --version

You should see the installed Python version.

Step 4: Install pip

If pip is not installed by default, install it using:

sudo apt install python3-pip

Verify the installation with:

pip3 --version

Step 5: Install a Code Editor (Optional)

You can install a code editor like Visual Studio Code or PyCharm. For Visual Studio Code, use:

sudo snap install --classic code

Creating a Virtual Environment

A virtual environment is a self-contained directory that contains a Python installation for a particular version of Python, plus a number of additional packages.

Windows

  1. Open Command Prompt.
  2. Navigate to your project directory.
  3. Run the following command to create a virtual environment: python -m venv myenv
  4. Activate the virtual environment: myenv\Scripts\activate

Linux

  1. Open a terminal.
  2. Navigate to your project directory.
  3. Run the following command to create a virtual environment: python3 -m venv myenv
  4. Activate the virtual environment: source myenv/bin/activate

Installing Packages

Once the virtual environment is activated, you can install packages using pip.

Example

To install the requests package, run:

pip install requests

Conclusion

You've successfully set up Python on your Windows or Linux system. You can now start developing Python applications and using various packages to enhance your projects.

Python Logo