Getting your Python environment wrong is the fastest way to kill your momentum before you write a single line of analysis code. This lesson walks you through installing Python, VS Code, and Jupyter correctly — and shows you why virtual environments are the professional habit that saves hours of future frustration.

Imagine you've just been handed a folder of CSV files — monthly sales reports, customer records, maybe some inventory data — and your manager wants a cleaned-up summary by Friday. You've heard Python can do in seconds what takes you an hour in Excel, but when you go to get started, you hit a wall of questions: Do I download Python from python.org or somewhere else? What's VS Code? What even is a "virtual environment"? The setup phase stops more people than the actual coding does.
That's exactly what this lesson fixes. We're going to walk through every step of getting a proper Python data analysis environment running on your machine, from zero to writing your first real line of pandas code. This isn't a cursory "just install Python and go" guide — we'll explain why each piece exists and how they all fit together, so you're not blindly following steps that break the moment something goes slightly differently on your computer.
By the end of this lesson, you'll have a professional-grade setup that mirrors how working data analysts actually operate. Every tool we install has a specific job, and you'll understand that job before you install it.
What you'll learn:
Before we touch a single installer, let's build a mental model of the tools involved. This is worth five minutes of your time, because it will save you hours of confusion later.
Think of your data analysis workflow as a kitchen. Python is the cooking technique — the fundamental skill that makes everything possible. VS Code is your kitchen itself — the workspace with all your counters, drawers, and good lighting where you actually do the work. Jupyter notebooks are a specific type of cooking journal where you can write a step, execute it immediately, see the result, and then write the next step. And virtual environments are like having separate sets of ingredients and tools for different recipes, so your Italian cooking supplies never accidentally contaminate your baking.
Each tool has a distinct role:
sales_total = sum(monthly_sales), Python is what makes that addition happen.Key insight
Many beginners install Python and start writing code directly in a global environment. This works until it doesn't — usually when two projects need different versions of the same package and they start breaking each other. Starting with virtual environments from day one is a professional habit worth building immediately.
Go to python.org/downloads in your browser. The site will detect your operating system and offer you the latest stable version. As of this writing, any Python 3.10, 3.11, or 3.12 release is excellent for data work. You want the "stable release" — not a pre-release or release candidate.
Warning
Do not install Python from the Microsoft Store if you're on Windows. It creates a sandboxed version with permission quirks that cause subtle problems when installing packages. Always download directly from python.org.
Click the download button for your OS and run the installer.
When the installer window opens, you'll see a checkbox at the very bottom that says "Add Python to PATH." Check this box before you do anything else. It's unchecked by default, and if you miss it, Python installs but your terminal won't be able to find it.
After checking that box, click "Install Now." The installer handles the rest.
Run the downloaded .pkg file and follow the prompts. After installation completes, open the Terminal application (find it in Applications → Utilities → Terminal) and run:
python3 --version
You should see something like Python 3.12.2. On macOS, the command is python3, not python, because older Macs had Python 2 installed by the system and Apple kept both names available.
Most Linux distributions come with Python 3 pre-installed. Verify with:
python3 --version
If you need to install or upgrade, use your package manager. On Ubuntu or Debian:
sudo apt update
sudo apt install python3 python3-pip python3-venv
Open a terminal (on Windows, search for "Command Prompt" or "PowerShell" in the Start menu) and type:
python --version
On macOS/Linux, use python3 --version. You should see your version number printed back. If you see an error like "python is not recognized," the PATH wasn't set correctly — on Windows, re-run the installer and ensure that checkbox is ticked.
You also want to verify pip, Python's package manager (the tool you use to install libraries like pandas):
pip --version
This should return a version number and a file path.
VS Code (Visual Studio Code) is a free code editor from Microsoft. Despite the "Microsoft" origin, it runs equally well on Windows, macOS, and Linux and has become the most widely used code editor in the world, across all programming languages.
Go to code.visualstudio.com and download the version for your operating system. Run the installer with default options.
VS Code is designed to work with many programming languages, so Python support is added through an extension. After VS Code opens:
This extension is what allows VS Code to understand Python syntax, run Python files, and connect to virtual environments.
While you're in the Extensions panel, also install the Jupyter extension by Microsoft. This lets you work with Jupyter notebooks directly inside VS Code — which is the workflow we'll use throughout this learning path.
Tip
VS Code will sometimes show a notification asking you to "Select a Python Interpreter" after installing the Python extension. Ignore this for now — we'll select the right interpreter after we create our virtual environment in a few minutes.
Before we create a virtual environment, let's establish where your project will live. Virtual environments are tied to specific project folders, so the folder comes first.
Open your terminal and navigate to wherever you keep your projects. If you're new to the terminal, here's what you need:
cd stands for "change directory" — it's how you navigate foldersmkdir creates a new folderls (macOS/Linux) or dir (Windows) lists what's in the current folderCreate a folder for this practice project:
cd Documents
mkdir data-analysis-practice
cd data-analysis-practice
Now open this folder in VS Code. You can do this from the terminal:
code .
The . means "current folder." VS Code will open with your data-analysis-practice folder loaded in the file explorer on the left.
Here's where many tutorials skip the explanation and just give you commands to copy. We're not doing that, because understanding this will save you real frustration.
When you install a package with pip install pandas, it installs pandas into your Python installation. If you install it globally (without a virtual environment), it goes into the system-wide Python. Now imagine you have two projects: one needs pandas version 1.5 for compatibility with some legacy code, and another project needs pandas version 2.1 for a new feature. They can't both be installed globally at the same time.
A virtual environment is a self-contained copy of Python with its own package directory. Project A activates its virtual environment and sees pandas 1.5. Project B activates its virtual environment and sees pandas 2.1. They never interfere.
Note
The virtual environment doesn't copy the entire Python interpreter each time — it mostly creates a folder structure with its own package storage and some small configuration files that point back to the base Python installation. They're lightweight.
In your terminal, make sure you're inside your data-analysis-practice folder. Then run:
python -m venv venv
On macOS/Linux:
python3 -m venv venv
Breaking this down: python -m venv tells Python to run its built-in venv module. The last word venv is the name of the folder it will create for your virtual environment. You could name it anything, but venv is the near-universal convention, and using it means other developers (and VS Code's auto-detection) will immediately recognize what that folder is.
After running this, you'll see a new folder called venv appear in your project directory. Don't edit anything inside it manually.
Creating the environment doesn't automatically switch you into it. You have to activate it:
Windows (Command Prompt):
venv\Scripts\activate
Windows (PowerShell):
venv\Scripts\Activate.ps1
macOS/Linux:
source venv/bin/activate
After activation, your terminal prompt will change. You'll see (venv) appear at the beginning of the line, like this:
(venv) C:\Users\YourName\Documents\data-analysis-practice>
That (venv) prefix is your confirmation that the virtual environment is active. Any pip install commands you run now will install packages into this environment only.
Warning
If you close your terminal and open a new one, you need to activate the virtual environment again. The activation doesn't persist between sessions. Many developers get caught by this — they wonder why their packages "disappeared" when they're actually just looking at the global Python again.
With your virtual environment active, install the core packages for data analysis:
pip install pandas openpyxl jupyter notebook
Let's clarify what each package does:
.xlsx). Without it, pd.read_excel() will fail with a confusing error.The installation will take a minute or two. You'll see a series of "Downloading..." and "Installing..." messages scroll by. That's normal.
Verify the installation worked:
pip list
This prints every package installed in your current environment. Scroll through and confirm you see pandas, openpyxl, jupyter, and notebook listed.
VS Code needs to know which Python interpreter (which virtual environment) to use for this project. Here's how to tell it:
venv in its path — something like Python 3.12.2 ('venv': venv) with a path pointing into your project folder.You'll see the selected interpreter appear in the bottom status bar of VS Code. This tells VS Code: "When I run Python code in this project, use this Python, not some other one."
Now let's bring everything together. Inside VS Code, with your project folder open:
exploration.ipynb. The .ipynb extension stands for "IPython Notebook," the historical name for Jupyter notebooks.A notebook is made up of cells. There are two main types:
The interactive, cell-by-cell execution model is what makes Jupyter invaluable for data exploration. You can load a dataset in one cell, clean it in the next, write a summary in a markdown cell, visualize it in another code cell — and at any point, re-run just the cell you're working on without re-running the whole script.
Click into the first empty cell. Make sure it's set to "Code" (VS Code shows this in a dropdown in the top-right of the cell). Type this:
import pandas as pd
# Create a small sample dataset representing monthly sales
data = {
'month': ['January', 'February', 'March', 'April', 'May'],
'region': ['North', 'North', 'South', 'South', 'North'],
'sales': [42300, 38900, 51200, 47800, 55100],
'units': [283, 261, 342, 319, 368]
}
df = pd.DataFrame(data)
df
Run the cell by pressing Shift+Enter or clicking the play button (triangle icon) that appears to the left of the cell when you hover over it.
You should see a table rendered below the cell, showing your data in a clean, spreadsheet-style format:
month region sales units
0 January North 42300 283
1 February North 38900 261
2 March South 51200 342
3 April South 47800 319
4 May North 55100 368
This is pandas in action. The pd.DataFrame() function created a structured table from your dictionary. The df at the end of the cell is how Jupyter knows to display it — in a regular Python script, you'd need print(df), but in a notebook, a bare variable or expression on the last line gets displayed automatically.
Tip
The standard convention is to import pandas as pd — you'll see this in virtually every piece of Python data analysis code in existence. It's not required, but deviating from it will make your code look odd to any collaborator.
Let's add one more cell. Press Shift+Enter with the cursor in the first cell (it runs the cell and creates a new one below), then type:
# Summary statistics for numeric columns
df.describe()
Run this cell and you'll see count, mean, standard deviation, min, and max for your sales and units columns. That's one line of code to get what would take several formulas in Excel.
Complete these steps to verify your setup is fully functional:
Part 1: Recreate the environment from scratch.
Create a new folder called sales-analysis. Navigate to it in your terminal, create a fresh virtual environment, activate it, and install pandas and jupyter.
Part 2: Build a notebook.
Open VS Code in the new folder, create a notebook called sales_summary.ipynb, and connect it to your virtual environment's interpreter.
Part 3: Write analysis code. In the notebook, create a DataFrame representing six months of sales data for two products of your choice. Include at minimum: a month column, a product column, a revenue column, and a quantity column. Then:
df.describe() to show summary statisticsdf['revenue'].sum() to print total revenuePart 4: Verify isolation.
Deactivate your virtual environment (deactivate in the terminal), then run pip list. Notice the packages look different — pandas likely isn't there. This confirms your project packages are isolated. Reactivate the environment to confirm pandas reappears in pip list.
You either didn't check "Add Python to PATH" during installation, or you installed from the Microsoft Store. Re-run the python.org installer, choose "Modify," and ensure PATH is included. Alternatively, search for "Environment Variables" in Windows settings and manually add Python's installation folder.
This almost always means VS Code is using the wrong Python interpreter — probably the global one instead of your virtual environment's. Go through the "Python: Select Interpreter" step again and confirm the path includes venv.
Your code is running in an environment where pandas isn't installed. Either your virtual environment isn't activated (check for the (venv) prefix in your terminal), or VS Code is pointing to the wrong interpreter. Check both.
If you see permission errors, you're likely accidentally installing into the system Python instead of your virtual environment. Verify activation and try again. Never use sudo pip install — it installs into the system Python as root, which can cause serious problems.
Windows PowerShell has a security policy that blocks unsigned scripts by default. Run this command once in PowerShell as Administrator:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Then try activating again.
Tip
If you're repeatedly hitting environment issues, the nuclear option is to delete the venv folder entirely and recreate it from scratch. Virtual environments are cheap to recreate — always check that your packages are correctly listed in pip list after recreating.
You've built a complete, professional Python data analysis environment. Let's recap what each piece does:
Every analyst working in Python uses some version of this setup. The habits you've built here — creating a virtual environment first, installing packages into it, connecting your editor to the right interpreter — will prevent entire categories of problems as your projects grow in complexity.
The next step in this learning path is getting comfortable with pandas fundamentals: loading real data from CSV and Excel files, understanding what a DataFrame actually is, and performing your first selections and filters. The environment you set up today is the launchpad for all of that work.
For day-to-day use, keep these commands in your back pocket:
# Start a new project
mkdir my-project && cd my-project
python -m venv venv
source venv/bin/activate # or venv\Scripts\activate on Windows
pip install pandas openpyxl jupyter
# Return to an existing project
cd my-project
source venv/bin/activate # activate every time you open a new terminal
code . # open VS Code
You're set up. Let's start analyzing data.
Python for Data Analysis