Python Vibe Coding Course — Part 2

Environment Setup

Run your first code with VSCode and a virtual environment

Illustration of a sprout growing from a terminal window under a glass dome

In this part, you will put the environment setup concepts from Part 1 into practice. You will install VSCode and Python, create a virtual environment inside your analysis folder, and finish by reading a sample Excel file and outputting its basic statistics. It takes about an hour. If errors appear, don't panic. Read each message on the screen carefully and work through it step by step.

Dr. Hoo, setting up an environment sounds hard.
Don't worry. It takes about an hour, one step at a time. If an error appears, stay calm and check what the screen says as you go.

What you need (all free)

  • VSCode (Visual Studio Code) A free code editor from Microsoft. Download it from code.visualstudio.com.
  • Python The Python interpreter. Install the latest stable version from python.org/downloads.
  • A sample Excel file Any spreadsheet with at least one sheet of numeric data (e.g., height, weight, age).
01

Install VSCode

Part 1 recap

VSCode is the code editor introduced in Part 1, the dedicated app for writing and running code. Along with syntax coloring and autocomplete, it lets you open a "terminal" for typing commands in the same window. Almost everything in this course happens inside VSCode.

Go to code.visualstudio.com, click "Download for Windows" (or Mac), and run the installer. Follow the on-screen instructions to complete the installation.

On Windows, the installer offers options such as "Add to PATH" and "Add to right-click menu." Checking all of these will make later steps easier.

02

Install Python

Is there anything to watch for when installing?
On Windows, be sure to check "Add python.exe to PATH." Without it, the terminal cannot find Python.

The "Python" you install here is the interpreter (execution engine) introduced in Part 1. It is the core piece that reads your code line by line and carries it out.

Download Python from python.org/downloads. The latest stable release (e.g., Python 3.12) is fine to start with.

The latest version is not always the best choice. Some libraries have not yet been updated for the newest Python version. If you need such a library, you may need to install a slightly older version (e.g., Python 3.10 or 3.11). Start with the latest version. If you later see a "this Python version is not supported" error, you can install a different version at that point (see Part 3 for instructions).

Important. On the Windows installer screen, make sure to check "Add python.exe to PATH". Without this, you cannot run Python from the terminal. No additional settings are needed on Mac.

Once installation is complete, verify it worked. Open VSCode, go to "Terminal → New Terminal" in the top menu, and type the command below.

Terminal
python --version

If you see something like Python 3.12.x, the installation was successful. On Mac, try python3 --version if the above doesn't work.

03

Create an analysis folder and put your Excel file in a data folder

Create a new folder somewhere convenient (e.g., on your Desktop). Give it a clear name like my_first_analysis.

Next, create a subfolder named data inside it, and place the Excel file you want to analyze (e.g., sample_data.xlsx) inside that data folder. If you don't have one handy, create a simple spreadsheet in Excel with column headers like "Height," "Weight," and "Age" and save it there.

Separating your raw data into a data folder from the start matches the folder structure you'll use in Part 5 when you publish your analysis alongside your paper. It saves you from reorganizing everything later.

Folder structure at this point

my_first_analysis/
└── data/
    └── sample_data.xlsx

04

Open the folder in VSCode

Launch VSCode and go to "File → Open Folder" in the top menu. Select the my_first_analysis folder you just created. You should see a data folder containing sample_data.xlsx in the left panel.

If prompted "Do you trust the authors of the files in this folder?", click "Yes, I trust the authors."

05

Install the "Python" and "Jupyter" extensions

Click the square icon in the left sidebar (Extensions). Search for and install the two extensions below.

  • Python (by Microsoft), for Python language support
  • Jupyter (by Microsoft), for working with .ipynb files

Just click the blue "Install" button for each.

For Windows users. If you see a "path too long" or "The filename or extension is too long" error when installing extensions or running pip install, the cause is the Windows limit on file path length. See the supplementary article Fixing the Windows "Long Path" Problem for the fix.

06

Create a virtual environment (venv)

What is a virtual environment for?
It is a separate Python workspace just for this folder. Library versions won't clash with other projects, and it helps with reproducibility later.

This is the most important step. A virtual environment is an isolated Python environment dedicated to this folder. It is the "work room" we pictured in Part 1, and here you actually build it. It prevents library versions from conflicting with other projects and helps keep your work reproducible later.

What exactly is a "terminal"?

A terminal is a window where you control your computer by typing text commands instead of clicking with the mouse. Tasks like installing Python or creating a virtual environment have no button to click, so you usually do them in the terminal. The "black window full of text" can look intimidating, but don't worry. In this course, you'll mostly just paste a one- or two-line command and press Enter.

Go to "Terminal → New Terminal" in the top menu. A terminal panel will open at the bottom.

Checking the terminal's "current location"

A terminal always knows which folder it is working in (its current directory). Terminals opened from VSCode start in the folder you have open in VSCode, so if you opened my_first_analysis in Step 4, the terminal starts there as well. The folder name shown just before the prompt tells you the current location, and every command from here on runs inside that folder.

If you ever find yourself in the wrong folder, move with cd path/to/project (for example, cd C:\Users\name\my_first_analysis). To see the full current path, use Get-Location on Windows or pwd on Mac/Linux.

Choosing a terminal type (Windows)

On Windows, you can choose between PowerShell, Command Prompt, Git Bash, and others. This course recommends PowerShell. Click the "∨" dropdown next to the "+" button at the top right of the terminal panel and select "PowerShell" (it is usually the default). On Mac/Linux, zsh or bash is selected automatically, so no change is needed.

Once the terminal is ready, run the command below (type it and press Enter).

Terminal (Windows / Mac)
python -m venv .venv

On Mac, use python3 -m venv .venv if python doesn't work. When the command finishes, a .venv folder will appear inside your project folder. This is the virtual environment itself.

Using a specific Python version. If you have multiple Python versions installed, you can specify which one to use. Use py -3.11 -m venv .venv on Windows, or python3.11 -m venv .venv on Mac/Linux. The specified version must already be installed.

Folder structure at this point

my_first_analysis/
├── .venv/           # Virtual environment (leave the contents alone)
└── data/
    └── sample_data.xlsx

07

Activate the virtual environment

What does it mean to activate it?
It means switching that workspace on. While it is active, pip install puts libraries inside it and nowhere else.

You need to "enter" the virtual environment you created. This is called activating it. While the environment is active, pip install installs libraries only inside it, and the python command uses that environment's Python. If you run pip install without activating first, the libraries are installed system-wide, and your projects are no longer kept separate.

Run the command for your system in the terminal.

Windows (PowerShell)
.venv\Scripts\Activate.ps1
Windows (Command Prompt)
.venv\Scripts\activate.bat
Mac / Linux
source .venv/bin/activate

If it works, you will see (.venv) at the start of your terminal prompt. This indicates the virtual environment is active. When (.venv) disappears, you are outside the environment (to exit manually, run deactivate).

If you see "running scripts is disabled on this system" in Windows PowerShell, run Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass once in the terminal, then try the activate command again.

08

Tell VSCode about the virtual environment (Select Kernel / Python Interpreter)

You also need to tell VSCode which Python environment to use for running code. There are two ways, depending on the file type.

  • Status bar (bottom right). When a .py file is open, the Python version appears in the bottom-right corner. Click it to see a list and select the entry containing .venv.
  • "Select Kernel" button (top right). When a .ipynb file (Jupyter Notebook) is open, a "Select Kernel" button appears in the top-right corner. Click it, choose "Python Environments," and select the entry containing .venv.

In this course, we primarily use .ipynb files, so you will mainly use the "Select Kernel" button in the top right.

If .venv doesn't appear in the list, try closing and reopening VSCode. If it still doesn't appear, the virtual environment may not have been created in Step 6. Check that the .venv folder exists directly inside your project folder.

09

Create an .ipynb file in a notebooks folder

First, click the "New Folder" icon in the left sidebar file explorer and create a folder named notebooks. Then, with that notebooks folder selected, click the "New File" icon (paper icon) and create a file named analysis.ipynb inside it. The .ipynb format is called a Jupyter Notebook. It lets you write code, see results, and add explanations in individual cells, which is why it is widely used in research and education.

Keeping your analysis code in a notebooks folder and your raw data in a data folder gives you the exact structure you'll publish in Part 5. Starting this way avoids the confusion of rearranging files later.

Folder structure at this point

my_first_analysis/
├── .venv/
├── data/
│   └── sample_data.xlsx
└── notebooks/
    └── analysis.ipynb    # Analysis script

10

Run Hello World

Click analysis.ipynb to open it. Type the following code into the first cell (a box for writing code). Run it by clicking the "▷" (play) button on the left or pressing Shift + Enter.

analysis.ipynb (Cell 1)
print("Hello, world!")

If Hello, world! appears below the cell, your Python environment is working correctly. Congratulations!

If prompted to "Select a Python kernel" on the first run, choose the .venv Python. If asked "Install ipykernel?", click "Install."

I see "Hello, world!" on the screen.
Congratulations. That shows your Python environment is working.
11

Install a library (pandas)

Part 1 recap

A library is a collection of useful tools that someone built and shared. pip install puts one into the virtual environment (the box) you are currently in. The pandas library you install here is the standard tool for working with tabular data.

Install pandas (for reading Excel files) and openpyxl (for Excel format support) into your virtual environment. Run the command below in the terminal while (.venv) is shown in the prompt.

Terminal
pip install pandas openpyxl

When the download and installation finish, the line "Successfully installed ..." appears. That means it worked.

These libraries are installed only inside this virtual environment. If you create a new .venv for a different project, you will need to install them there separately. This is how each project keeps its own library versions.

12

Import and use a library

As touched on in Part 1, installing a library is not enough. You also need an import statement to declare that you will use it. Add a new cell in analysis.ipynb (click "+ Code" below the previous cell) and run the code below.

analysis.ipynb (Cell 2)
import pandas as pd print(pd.__version__)

If a version number (e.g., 2.2.0) appears below the cell, it worked. import pandas as pd means "use the pandas library under the short name pd." From this point on, you call its features by putting pd. in front, as in pd.read_excel(...).

13

Read the Excel file and output basic statistics

Now let's work with real data. Enter the following code in a new cell and run it. Replace sample_data.xlsx with your actual filename.

analysis.ipynb (Cell 3)
df = pd.read_excel("../data/sample_data.xlsx") df.head()
Why "../data/"?

The analysis.ipynb file you have open lives inside the notebooks folder, while your data sits in the neighboring data folder. The leading .. means "go up one level" (back to the my_first_analysis project folder). From there you step into data, so the path is ../data/sample_data.xlsx. When you point to a file in code, always think of it as "directions starting from where the notebook currently sits."

If the first five rows of your Excel file appear as a table, it worked. df (DataFrame) is what pandas calls the table it creates when it reads your file.

Now output the basic statistics.

analysis.ipynb (Cell 4)
df.describe()

For each column, you will get the count, mean, standard deviation (std), minimum (min), quartiles (25%, 50%, 75%), and maximum (max) all at once.

You are now doing data analysis in Python. In Part 3, you will learn how to have an LLM (large language model) write more complex analyses for you.


✓

What you can now do

  • Install VSCode and Python
  • Create a virtual environment (venv) and activate it
  • Install libraries with pip install inside a virtual environment
  • Call a library in code with import
  • Run code cell by cell in an .ipynb file
  • Read an Excel file and output basic statistics

In Part 3, you will use this cell-by-cell execution style to have an LLM write code while you work through your analysis.

I read an Excel file and printed basic statistics.
You are already analyzing data with Python. In Part 3, an LLM will help with more complex analyses.