In this part, you will create a project-specific Python virtual environment named .venv, install the packages listed by the course repository, and configure Visual Studio Code to use that environment for Python and Jupyter notebooks.
The environment belongs to this project and stays on your computer. It will not be uploaded to GitHub.
By the end of this part, you should have:
- a
.venvenvironment inside the course repository; - Python 3.13 running inside that environment;
- the course packages from
requirements.txtinstalled; ipykernelavailable for Jupyter notebooks;.venvexcluded from Git tracking;.venvselected as the VS Code Python interpreter; and.venvselected as the VS Code notebook kernel.
A Python virtual environment is an isolated Python installation for one project.
Your course environment will be stored here:
3603-data-science-yourlastname/
├── .venv/
├── requirements.txt
├── Assignments/
├── Completed/
└── other course files
The .venv folder contains:
- a Python interpreter;
pip;- the packages needed by the course; and
- scripts used to activate the environment.
It does not contain your notebooks or other course work.
Python’s documentation describes virtual environments as isolated, disposable, and unsuitable for committing to source control. If an environment breaks, it should be recreated from requirements.txt rather than repaired package by package. See the official venv documentation.
For this course:
Environment name: .venv
Package manager: pip
Package list: requirements.txt
Do not create several environments with names such as:
venv
env
test-env
myenv
base
Do not use Conda for this repository.
Open Visual Studio Code and open your local course folder.
If you are starting from a terminal, move into the repository using your actual folder name:
cd ~/Projects/3603-data-science-YOURLASTNAMEThen open it in VS Code:
code .Open a new terminal in VS Code with Terminal → New Terminal.
Windows students must confirm that this is a Git Bash terminal rather than PowerShell.
Verify that the terminal is inside the repository:
pwd
git statusCheck that the requirements file exists:
ls requirements.txtExpected output:
requirements.txt
If the file is not found, stop. You are probably in the wrong folder.
Look at the beginning of the terminal prompt.
This indicates that Conda is active:
(base) student@computer ...
If (base) or another Conda environment appears, deactivate it:
conda deactivateDisable automatic base activation:
conda config --set auto_activate_base falseClose the terminal and open a new one. The (base) prefix should be gone before continuing.
Do not create .venv while a Conda environment is active. That produces an unnecessarily confusing environment whose base interpreter may not be the course Python installation.
Use the command for your operating system.
py -V:3.13 -m venv .venvThis explicitly creates the environment with standard Python 3.13, even if other Python versions are installed.
python3.13 -m venv .venvThe command may take a few seconds and may produce no output when successful.
Run:
ls -aYou should see .venv in the listing.
Do not manually place notebooks or other files inside .venv.
Activation changes the terminal so that python and pip refer to the project environment.
Use the command for your operating system.
source .venv/Scripts/activatesource .venv/bin/activateThe prompt should now begin with:
(.venv)
For example:
(.venv) student@computer ...
If the prompt begins with both (base) and (.venv), stop and deactivate both environments. Then close the terminal, open a new terminal, and activate only .venv.
After activation, the same verification commands work on Windows and macOS.
Check the version:
python --versionExpected output resembles:
Python 3.13.x
Display the exact interpreter location:
python -c "import sys; print(sys.executable)"The result must contain your repository’s .venv folder.
Windows output will resemble:
C:\Users\student\Projects\3603-data-science-smith\.venv\Scripts\python.exe
macOS output will resemble:
/Users/student/Projects/3603-data-science-smith/.venv/bin/python
If the path does not contain .venv, the environment is not active. Do not install packages until this check succeeds.
Verify pip:
python -m pip --versionIts displayed location must also be inside .venv.
Run:
python -m pip install --upgrade pipThis upgrades pip only inside the project environment.
Do not use:
sudo pip install ...Do not install the course packages globally.
The repository contains requirements.txt, which lists packages needed for the course.
Install the complete list:
python -m pip install -r requirements.txtPackage installation may take several minutes. Lines of output will appear as packages are downloaded and installed.
Successful installation normally ends with a message beginning with:
Successfully installed ...
Some packages may report:
Requirement already satisfied
That is not an error. It means the required package is already present in .venv.
The -r option tells pip to install the package specifications from a requirements file. See the official pip requirements instructions.
Do not run:
pip freeze > requirements.txtThe instructor’s requirements file defines the course environment. Students should not replace it with a list generated from one computer.
VS Code requires ipykernel to run the selected Python environment as a Jupyter notebook kernel.
Run:
python -m pip install ipykernelIf ipykernel was already included in requirements.txt, pip will report that the requirement is already satisfied.
The full Jupyter application does not need to be installed globally. VS Code’s Jupyter extension can use a Python environment when ipykernel is available. See VS Code’s Jupyter kernel documentation.
Check for incompatible installed dependencies:
python -m pip checkExpected output:
No broken requirements found.
Display the installed packages if you need to inspect them:
python -m pip listVerify several packages commonly used in the course:
python -c "import numpy, pandas, matplotlib, seaborn, sklearn, ipykernel; print('Course packages imported successfully.')"Expected output:
Course packages imported successfully.
If this command reports a missing package, use the troubleshooting section before installing random packages individually.
The virtual environment contains many generated files and must not be uploaded to GitHub.
Ask Git whether a file inside .venv is ignored:
git check-ignore -v .venv/pyvenv.cfgIf the command prints an ignore rule and a path, .venv is ignored.
Also check repository status:
git status --shortThe output should not list thousands of .venv files.
Open the repository’s root .gitignore file in VS Code and add:
# Local Python virtual environment
.venv/Save .gitignore, then verify again:
git check-ignore -v .venv/pyvenv.cfg
git status --shortOnly .gitignore should appear as a changed file. The .venv contents should not appear.
Do not use git add -f to force .venv into the repository.
Visual Studio Code needs to know which Python interpreter belongs to the project.
- Open the Command Palette:
- Windows:
Ctrl+Shift+P - macOS:
Cmd+Shift+P
- Windows:
- Run Python: Select Interpreter.
- Choose the interpreter whose path contains the current repository and
.venv.
The choice may be labeled:
Python 3.13.x ('.venv': venv)
or may display a path ending in:
.venv\Scripts\python.exe
.venv/bin/python
The selected environment appears in the VS Code status bar. VS Code uses it for running Python, IntelliSense, debugging, and related language features. See Python environments in VS Code.
- Confirm that the repository folder—not merely one notebook—is open in VS Code.
- Confirm that
.venvexists in the repository root. - Open the Command Palette and run Developer: Reload Window.
- Run Python: Select Interpreter again.
- Choose Enter interpreter path if necessary and browse to the interpreter inside
.venv.
Open one of the course .ipynb files in Visual Studio Code.
- Select Select Kernel in the upper-right corner of the notebook.
- If
.venvappears immediately, select it. - Otherwise, select Select Another Kernel.
- Select Python Environments.
- Choose the Python 3.13 environment whose path contains
.venv.
VS Code remembers the selected kernel for the notebook.
Do not select:
- a global Python installation;
- Apple’s system Python;
- a Conda
baseenvironment; - an environment from another course; or
- an interpreter whose path does not contain this repository’s
.venv.
Create a temporary unsaved notebook:
- Open the Command Palette.
- Run Create: New Jupyter Notebook.
- Select
.venvas the kernel if it is not already selected. - Enter the following code in the first cell:
import sys
import matplotlib
import numpy
import pandas
import seaborn
import sklearn
print(sys.version)
print(sys.executable)
print("Jupyter environment is ready.")- Run the cell.
The interpreter path printed by the notebook must contain .venv, and the final line should be:
Jupyter environment is ready.
Close this temporary notebook without saving it. Do not use a graded course notebook as an environment test.
Deactivate the terminal environment:
deactivateThe (.venv) prefix should disappear.
Reactivate it when returning to the project.
source .venv/Scripts/activatesource .venv/bin/activateVS Code may automatically activate the selected environment when it creates a new terminal. Even so, always confirm that the terminal prompt begins with (.venv) or verify sys.executable before installing packages.
Each time you work on the course:
- Open the repository folder in VS Code.
- Open a terminal.
- Activate
.venvif VS Code did not activate it automatically. - Confirm the notebook kernel is
.venv. - Work on the notebook.
- Deactivate the environment when finished if desired.
The environment does not need to be recreated each day.
The .venv directory is generated from Python and requirements.txt. It is disposable.
Recreate it when:
- it was created with the wrong Python version;
- it was copied or moved from another computer;
- the repository folder was moved and the environment stopped working;
- package installation was interrupted and left inconsistent results;
- VS Code persistently selects an interpreter that no longer exists; or
- the environment contains unexplained dependency conflicts.
-
Save all notebooks and source files.
-
Close running notebook kernels.
-
Deactivate the environment:
deactivate
-
Verify that the folder you intend to remove is exactly
.venvinside the course repository. -
Delete only the
.venvfolder using the VS Code Explorer or your operating system’s file manager. -
Recreate it with the correct command.
py -V:3.13 -m venv .venv
source .venv/Scripts/activatepython3.13 -m venv .venv
source .venv/bin/activate-
Reinstall packages:
python -m pip install --upgrade pip python -m pip install -r requirements.txt python -m pip install ipykernel python -m pip check
-
Select the recreated
.venvinterpreter and kernel in VS Code.
Deleting .venv does not delete notebooks or Git history, provided you delete only that exact generated folder.
You are probably in the wrong folder.
Run:
pwd
ls
git statusMove to the repository root before installing:
cd ~/Projects/3603-data-science-YOURLASTNAMEConfirm that you are using the course’s standard Python 3.13 installation.
py -V:3.13 --versionpython3.13 --versionIf the command fails, return to Part 2 and repair the base Python installation.
Confirm all of the following:
- the terminal profile is Git Bash;
- the current folder is the repository root;
.venvwas created successfully; and- the activation path uses
Scriptswith a capitalS.
Inspect the folder:
ls .venv/ScriptsIf you are in PowerShell, close that terminal and open Git Bash. Do not change PowerShell execution policy for this course workflow.
Confirm the folder exists:
ls .venv/binIf it does not, recreate .venv using python3.13 -m venv .venv.
Run:
python -c "import sys; print(sys.executable)"The interpreter path is more reliable than the appearance of the prompt. If the path does not contain .venv, activate the environment again.
Check the active interpreter:
python -c "import sys; print(sys.executable)"If the path does not contain .venv, activate the environment before installing.
Do not solve the problem with sudo, administrator mode, or a global package installation.
First verify the interpreter:
python --version
python -c "import sys; print(sys.executable)"Confirm that it is standard Python 3.13 inside .venv, not a prerelease or free-threaded build.
Then upgrade pip and retry the requirements installation:
python -m pip install --upgrade pip
python -m pip install -r requirements.txtIf the same package fails again, record the complete error and show it to the instructor. Do not substitute an arbitrary package version.
Open:
/Applications/Python 3.13/
Run:
Install Certificates.command
Then close and reopen the terminal, reactivate .venv, and retry.
- Select the kernel name in the notebook’s upper-right corner.
- Select Select Another Kernel.
- Select Python Environments.
- Choose the interpreter inside the repository’s
.venv.
Verify from a notebook cell:
import sys
print(sys.executable)Activate .venv and run:
python -m pip install ipykernelReload VS Code and select the .venv kernel again.
The terminal and notebook are using different interpreters.
Compare:
python -c "import sys; print(sys.executable)"import sys
print(sys.executable)Both paths must point into the same .venv folder.
Do not stage or commit them.
Add this line to the repository’s root .gitignore:
.venv/Then run:
git status --shortIf .venv files were already staged, ask the instructor for help before continuing. Do not use a force-add command.
Deactivate environments until both labels disappear:
deactivate
conda deactivateClose the terminal, open a new terminal, verify that (base) is absent, and activate only .venv.
With .venv activated, run:
python --version
python -c "import sys; print(sys.executable)"
python -m pip --version
python -m pip check
python -c "import numpy, pandas, matplotlib, seaborn, sklearn, ipykernel; print('Course environment is ready.')"
git check-ignore -v .venv/pyvenv.cfg
git status --shortConfirm that:
- Python reports version 3.13;
- the interpreter path contains
.venv; pipis inside.venv;- no broken requirements are reported;
- the import test succeeds;
- Git ignores
.venv; and - Git does not list
.venvcontents as changes.
- I created
.venvinside the course repository. - I created it with standard Python 3.13.
- My terminal can activate
.venv. -
pythonpoints inside.venvafter activation. - I upgraded
pipinside.venv. - I installed
requirements.txtsuccessfully. - I installed or verified
ipykernel. -
python -m pip checkreports no broken requirements. - The course-package import test succeeds.
- Git ignores
.venv. - VS Code uses
.venvas its Python interpreter. - VS Code uses
.venvas its notebook kernel. - A temporary notebook cell ran successfully.
- Conda is not active.