Python Essentials for Data Analytics
Back to PYTHON SETUP & ENVIRONMENT

Setting Up Your Python Environment (VS Code, venvs & pip)

4 minutesReading
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.

Setting Up Your Python Environment (VS Code, Virtual Envs & pip)

Before writing Python code for data analysis, having a clean, reproducible development environment is essential. This guide walks you through setting up Python across operating systems, installing VS Code, configuring isolated virtual environments, and managing packages with pip.


1. Verifying Your Python Installation

Open your command line interface (Terminal on macOS/Linux, PowerShell or Command Prompt on Windows) and run:

python --version
# or on macOS/Linux:
python3 --version

You should see Python 3.10.x or higher. If Python is not recognized:

  • Windows: Download the latest installer from python.org. Make sure to check the box "Add Python to PATH" before clicking Install.
  • macOS: Install via Homebrew: brew install python.
  • Linux (Ubuntu/Debian): Run sudo apt update && sudo apt install python3 python3-pip python3-venv.

2. Setting Up Visual Studio Code (VS Code)

While Jupyter Notebook in the browser is great for quick exploration, professional data analysts write scripts and notebooks directly in VS Code:

  1. Download and install Visual Studio Code from code.visualstudio.com.
  2. Open VS Code and navigate to the Extensions tab (Ctrl+Shift+X on Windows/Linux, Cmd+Shift+X on macOS).
  3. Search for and install the official Python extension (by Microsoft).
  4. Search for and install the official Jupyter extension (by Microsoft) to create and edit .ipynb files directly inside VS Code.

3. Why Virtual Environments Matter (venv)

When you install packages globally on your system using pip install pandas, package versions can conflict across different projects (e.g., Project A needs pandas 1.5, while Project B needs pandas 2.2). A Virtual Environment creates an isolated Python sandbox for your project.

Creating and Activating a Virtual Environment

  1. Navigate to your project directory in terminal:
    mkdir my_data_project
    cd my_data_project
  2. Create a virtual environment named .venv:
    python -m venv .venv
    # On macOS/Linux if python3 is default:
    python3 -m venv .venv
  3. Activate the environment:
    • Windows (PowerShell): .venv\Scripts\Activate.ps1
    • Windows (CMD): .venv\Scripts\activate.bat
    • macOS / Linux: source .venv/bin/activate

When activated, your terminal prompt will show (.venv) at the beginning of the line.


4. Package Management with pip

With your virtual environment activated, install the core data analysis stack:

pip install pandas numpy jupyter

Saving and Recreating Dependencies

  • Export all installed packages and their exact versions to a file:
    pip freeze > requirements.txt
  • Install all dependencies from a requirements.txt file in a new environment:
    pip install -r requirements.txt

Key Summary Checklist

Task Command / Action
Verify Python python --version or python3 --version
Create Virtual Env python -m venv .venv
Activate (Windows) .venv\Scripts\Activate.ps1
Activate (Mac/Linux) source .venv/bin/activate
Install Core Stack pip install pandas numpy jupyter
Deactivate Env deactivate
Loading progress...