4,222 Introduction to Programming
Recap Quiz week 1: Getting Started with Python and uv
This is a non-graded recap quiz to reinforce concepts from lecture 01b. Estimated time: 15-20 minutes. Ideally, complete this before starting Exercise 2 (git).
Exercise 2: Understand your environment
Answer the following questions by inspecting files and using the terminal. No coding required.
- Open the
pyproject.tomlfile in VS Code (the one created in Exercise 1). What Python version is specified? What dependencies are listed? - Where is the Python interpreter located in your
.venvfolder? Give the full path. - What does
uv add pandasdo? - If you delete the
.venvfolder, how would you recreate the environment? (Hint: think about which filesuvuses to know what to install.)
Open
pyproject.tomlin VS Code. Under[project], you should seerequires-python = ">=3.14.1". Underdependencies, you should seeipykernel,pandas, andnumpy.The Python interpreter path:
Introduction_to_programming\exercises\week_01\.venv\Scripts\python.exe
Introduction_to_programming/exercises/week_01/.venv/bin/python
uv add pandasinstalls the package inside the project’s virtual environment and records it inpyproject.tomlanduv.lock.One way is to run
uv init --python 3.14.1thenuv add <package>for each dependency listed inpyproject.toml. Another way, which we haven’t see specifically in the exercises, is to recreate the environment by runninguv syncin the project directory.uvreadspyproject.tomlanduv.lockto reinstall the exact same packages and Python version.
Exercise 3: Create a project folder
Navigate to exercises/week_01_recap/ (create the folder if it doesn’t exist yet). Initialize a uv project with Python 3.14.1 and add the ipykernel package. Then answer:
- Does this project share the same
.venvas yourweek_01project? Check by looking at the.venvfolders. - Run
uv run python -c "import pandas; print(pandas.__version__)"insideweek_01_recap. What happens and why? - Now go back to
week_01and run the same command. What happens and why?
cd exercises\week_01_recap
uv init --python 3.14.1
uv add ipykernel
uv run python -c "import pandas; print(pandas.__version__)"
cd ..\week_01
uv run python -c "import pandas; print(pandas.__version__)"cd ~/Documents/Introduction_to_programming/exercises/week_01_recap
uv init --python 3.14.1
uv add ipykernel
uv run python -c "import pandas; print(pandas.__version__)"
cd ../week_01
uv run python -c "import pandas; print(pandas.__version__)"No. Each project has its own
.venvfolder.week_01_recap/.venvandweek_01/.venvare separate, isolated environments.Inside
week_01_recap, the command fails withModuleNotFoundError: No module named 'pandas'. We only addedipykernelto this project, notpandas.Back in
week_01, the command prints the version ofpandas(e.g.,2.2.3). We addedpandastoweek_01in the previous exercise session. This demonstrates why virtual environments exist: each project is isolated and only has the packages you explicitly added to it.