#267: uv - The Fast Pip Replacement
If we dive into machine learning, we quickly run into a problem: Incompatible package versions. We can solve that problem with virtual environments, but that brings us right to the next one. Pip is a great tool, but when we need to install the same package multiple times, pip will download the package again and again. That is slow and breaks the flow. Let us explore an alternative solution.
uv – like pip but much faster
There are many options we can choose from to install packages. I heard about a tool called uv on TalkPython and could use it immediately. Unlike many other alternatives, we can reuse most of the commands we know from pip and still get a massive performance boost. That is why I did not bother to look further and go with uv.
We can install uv with this command:
# On macOS and Linux.
curl -LsSf https://astral.sh/uv/install.sh | sh
# On Windows.
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
This installs uv with the standalone installer, that offers us an option to update itself:
If you install uv with pip or another package manager, you cannot use the self-update feature. Instead, you need to use the same package manager that you used to install it.
Fix os error 5
If you use uv on Windows, you may end up with an os error 5 and an access denied exception. Should this happen, it is probably Windows Defender that blocks the access. Check the exception and add the path that was not accessible as an exception to Windows Defender. That should solve the problem.
uv to create virtual environments
We can create a new virtual environment with this command:
To activate the environment, we can use this script:
If we want to try the newest Python version (or a specific one), we can do so without installing that version by hand – uv does everything for us. All we need to do is to specify the version when we create the virtual environment:
Find available Python versions
We can use this command to see the available Python versions that can run on our machine:
uv python list
cpython-3.14.0a5+freethreaded-windows-x86_64-none <download available>
cpython-3.14.0a5-windows-x86_64-none <download available>
cpython-3.13.2+freethreaded-windows-x86_64-none <download available>
cpython-3.13.2-windows-x86_64-none <download available>
cpython-3.12.9-windows-x86_64-none <download available>
cpython-3.12.1-windows-x86_64-none C:\Users\jg\AppData\Local\Programs\Python\Python312\python.exe
cpython-3.11.11-windows-x86_64-none <download available>
cpython-3.10.16-windows-x86_64-none <download available>
cpython-3.9.21-windows-x86_64-none <download available>
cpython-3.8.20-windows-x86_64-none <download available>
cpython-3.7.9-windows-x86_64-none <download available>
pypy-3.11.11-windows-x86_64-none <download available>
pypy-3.10.19-windows-x86_64-none <download available>
pypy-3.9.19-windows-x86_64-none <download available>
pypy-3.8.16-windows-x86_64-none <download available>
pypy-3.7.13-windows-x86_64-none <download available>
uv as a pip replacement
We can use the most common pip commands with uv. All we need to do is to add uv in front of the pip command we want to use.
To install a package, we can use this command:
To update a package, we can do this:
If we want to remove a package, we can type this:
When we want to pin the version of the packages we have in our virtual environment, we can use this command:
To restore the packages, we can use this command:
As we seen so far, uv works best inside a virtual environment. If we try to use uv outside, we can, but it takes the additional parameter --system. Otherwise, we get this error:
uv pip install requests
error: No virtual environment found; run `uv venv` to create an environment,
or pass `--system` to install into a non-virtual environment
Next
With uv we get a fast replacement for pip that does a lot more than just managing packages. We can install Python versions, create virtual environments, and manage packages. Next week we explore the project management site of uv and see how that can help us.