As noted in the opening slides presentation: “A virtual environment keeps each project’s packages separate and organized, preventing conflicts and making your code easy to share.”
2c. Create Virtual Environment
Make sure you are in the project root folder, i.e. your terminal should look like something like this (with a path to your project directory shown):

If you are not in the project root directory you can navigate to it by using the cd (change directory) command. Some tips:
- to navigate up one directory type
cd ..
- to navigate up 3 directories type
cd ../../..
- to navigate from the current working directory into your code folder type
cd code.
- to navigate down two directories, type something like this:
cd code/scripts (assuming the code folder is in your current working directory and a scripts folder is inside of that).
Now, run the following in your project’s root directory from the terminal:
# This initiaties a new uv environment for your project
uv init
You will see in the Explorer pane on the left side of VSC several new files and folders were created in your project’s working directory. The above command:
Installed Python if the correct version isn’t available
Created a pyproject.toml file, where uv will store information about the packages / dependencies used in this project.
Created a .python-version file to store the version of Python used for this project.
2d. Install / add packages to virtual environment
Initiating uv may also create a uv.lock file and a '.venv folder if you have already installed some packages. Let’s test this out by installing a package to our local environment at which point this file and folder will be created:
Run in the terminal:
uv add requests
Certainly, now you should see the following in your project’s root directory:
a uv.lock file which may be used by others (or by yourself in a different environment) to reproduce the exact same computing environment for your project.
a .venv folder where the code for all projects added to the local environment are stored
You can also install / add multiple packages at once:
uv add numpy pandas rich
You can use uv remove to uninstall packages. We really didn’t need requests. Let’s uninstall it:
uv remove requests
You can review what packages have been installed in multiple ways. You can open either the pyproject.toml or the uv.lock file. Or you can run the following in the terminal:
uv pip list
You should see something like this:
Package Version
--------------- -----------
markdown-it-py 4.0.0
mdurl 0.1.2
numpy 2.4.1
pandas 2.3.3
pygments 2.19.2
python-dateutil 2.9.0.post0
pytz 2025.2
rich 14.2.0
six 1.17.0
tzdata 2025.3
*Note: the .toml file and uv pip list return all packages installed including dependencies. For example, when we installed rich, UV also installed the packages rich depends on: markdown-it-py, mdurl, and pygments. In contrast, the uv.lock just lists the actual packages that you, the user, installed:
dependencies = [
"numpy>=2.4.1",
"pandas>=2.3.3",
"rich>=14.2.0",
]
This is because uv.lock serves as instructions for the re-creation of this environment on another computer. If you were to open this project on a different computer, you would run the command uv sync, which would recreate your environment by installing the specific versions of numpy, pandas, and rich you have installed on your machine. When those are installed, their dependencies will be automatically installed as well.
Now, try running this:
pip list
Notice any difference from the results returned by uv pip list? In my case this second command returned many, many more packages. Why? It’s because the uv command automatically retrieves the names of packages installed to the local virtual environment, whereas pip retrieves all packages installed. That is why, under the pip system, you need to activate your virtual environment with .venv/Scripts/activate (Windows) or .venv/bin/activate (Macs) every time you open a project. Fortunately, with uv, we are automatically using the virtual environment whenever we call uv within a project that has one.