uv Exercises#
To go through these exercises, you need to create a new folder on your Desktop called bobiac_uv.
Exercise 1#
Step 1#
Create a Python Environment with uv and Install numpy & matplotlib
Open the Terminal or PowerShell and navigate to the
bobiac_uvfolder.Create a new virtual environment with
uvin thebobiac_uv_envfolder named.venv.Activate the newly created
.venvvirtual environment.Install
numpyandmatplotlibin the.venvvirtual environment.List the installed packages in the
.venvvirtual environment to confirm thatnumpyandmatplotlibare installed.Deactivate the
.venvvirtual environment.
Solution
open the Terminal or PowerShell.
cd .../Desktop/bobiac_uvuv venv .venv(or simplyuv venv)source .venv/bin/activate(Linux/macOS) or.venv\Scripts\activate(Windows)uv pip install numpy matplotlibuv pip listdeactivate
Step 2#
Add to the environment created in Step 1 the scikit-image package
Open the Terminal or PowerShell and navigate to the
bobiac_uvfolder.Activate the
.venvvirtual environment created in Step 1.Add the
scikit-imagepackage to the.venvvirtual environment.List the installed packages in the
.venvvirtual environment to confirm thatscikit-imageis installed.Deactivate the
.venvvirtual environment.
Solution
open the Terminal or PowerShell.
cd .../Desktop/bobiac_uvsource .venv/bin/activate(Linux/macOS) or.venv\Scripts\activate(Windows)uv pip install scikit-imageuv pip listdeactivate
Exercise 2#
Create a .py file with the PEP723 ///script header using uv
Open the Terminal or PowerShell and navigate to the
bobiac_uvfolder.Inside the
bobiac_uvfolder, create a new folder namedpy_folderand navigate into it.Use
uvto create a new Python file namedbobiac_script.pywith the PEP723///scriptheader and Python3.13.Add
numpyandmatplotlibas dependencies to thebobiac_script.pyfile usinguv.Run the
bobiac_script.pyfile usinguvto verify that the dependencies are installed and the script runs without errors.Optional: show the dependencies of the
bobiac_script.pyfile usinguv tree.Optional: show the python version used for the
bobiac_script.pyfile usinguv python.
Solution
open the Terminal or PowerShell.
cd .../Desktop/bobiac_uvmkdir py_foldercd .../Desktop/bobiac_uv/py_folderuv init --script bobiac_script.py -p 3.13uv add --script bobiac_script.py numpy matplotlibuv run bobiac_script.pyOptional:
uv tree --script bobiac_script.pyOptional:
uv python find --script bobiac_script.py --show-version