Python Vibe Coding Course — Part 2
Run your first code with VSCode and a virtual environment
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. Estimated time: about 1 hour. If errors appear, don't panic — check each screen message carefully and work through it step by step.
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.
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 and, if you encounter 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, Python cannot be called from the terminal. No additional settings are needed on Mac.
Once installation is complete, verify it worked. Open VSCode, go to the top menu "Terminal → New Terminal," and type:
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.
Create a new folder somewhere convenient (e.g., on your Desktop). Give it a clear name like my_first_analysis.
Place the Excel file you want to analyze (e.g., sample_data.xlsx) inside this 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.
my_first_analysis/
└── sample_data.xlsx
Launch VSCode and go to "File → Open Folder" in the top menu. Select the my_first_analysis folder you just created. You should see sample_data.xlsx listed in the left panel.
If prompted "Do you trust the authors of the files in this folder?", click "Yes, I trust the authors."
Click the square icon in the left sidebar (Extensions). Search for and install the following two extensions:
Just click the blue "Install" button for each.
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, this is caused by Windows's file path length limit. See the supplementary article Fixing the Windows "Long Path" Problem for the fix.
This is the most important step. A virtual environment is an isolated Python environment dedicated to this folder. It prevents library versions from conflicting with other projects and enables reproducibility.
Go to "Terminal → New Terminal" in the top menu. A terminal panel will open at the bottom.
On Windows, you can choose between PowerShell, Command Prompt, Git Bash, and others. This course recommends PowerShell. Click the "∨" dropdown next to the "+" button in the terminal panel and select "PowerShell" (it is usually the default). On Mac/Linux, zsh or bash is selected automatically — no change needed.
Once the terminal is ready, run the following command (type it and press Enter):
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.
To create a virtual environment with a specific Python version: If you have multiple Python versions installed, you can specify which one to use. On Windows: py -3.11 -m venv .venv; on Mac/Linux: python3.11 -m venv .venv. The specified version must already be installed.
my_first_analysis/
├── .venv/ # Virtual environment (leave the contents alone)
└── sample_data.xlsx
You need to "enter" the virtual environment you created — this is called activating it. When activated, any pip install command installs libraries only inside that environment, and the python command uses that environment's Python. Without activating first, libraries are installed system-wide and the project isolation is lost.
Run the appropriate command for your system in the terminal:
.venv\Scripts\Activate.ps1
.venv\Scripts\activate.bat
source .venv/bin/activate
When successful, 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" on Windows PowerShell, run Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass once in the terminal, then try the activate command again.
You also need to tell VSCode which Python environment to use for running code. There are two ways depending on the file type:
.venv..ipynb file (Jupyter Notebook) is open, a "Select Kernel" button appears in the top-right corner. Click it → "Python Environments" → 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 creation in Step 6 may have failed — check that the .venv folder exists directly inside your project folder.
Click the "New File" icon (paper icon) in the left sidebar file explorer and create a file named analysis.ipynb. The .ipynb format is called a Jupyter Notebook — it lets you write code, see results, and add explanations in individual cells, making it widely used in research and education.
my_first_analysis/
├── .venv/
├── analysis.ipynb # Analysis script
└── sample_data.xlsx
Click analysis.ipynb to open it. Type the following code into the first cell. Run it by clicking the "▷" (play) button on the left or pressing Shift + Enter.
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."
Install pandas (for reading Excel) and openpyxl (for Excel format support) into your virtual environment. Run the following in the terminal while (.venv) is shown in the prompt:
pip install pandas openpyxl
When the download and installation finish, you should see "Successfully installed ..." — 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 project-specific version isolation works.
Installing a library is not enough — you need to declare you're using it with an import statement. Add a new cell in analysis.ipynb (click "+ Code" below the previous cell) and run:
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 with pd.read_excel(...) and so on.
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.
df = pd.read_excel("sample_data.xlsx")
df.head()
If the first 5 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:
df.describe()
For each column, you will get 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 write more complex analyses for you.
pip install inside a virtual environmentimportIn Part 3, you will use this cell-by-cell execution style to have an LLM write code while you work through your analysis.