Installing and Removing Packages
00:00
Now it’s time to talk about one of the main selling points of uv, at least for a lot of users. And it is the package installation piece. And the table on the slide shows that uv is fast and pip slow, but this is not a fair assessment because fast and slow depends on a lot of factors, namely your network status, the processes running on your computer, whether uv or pip have a warm cache already.
00:25 So instead of just going with this overly simplistic table, you’ll see how fast or slow these tools really are.
00:32 What I have here is a folder that has absolutely nothing inside, so there’s no tricks up our sleeves.
00:39
And now we will time the installation of jupyterlab using pip with no cache. For that, let’s just quickly create a virtual environment so that we can install jupyterlab into the virtual environment.
00:52
And now to time the execution, we use the command time. And what do we want to time? Well, we want to take the pip that’s in this virtual environment and we want to install jupyterlab.
01:04
And you have the option --no-cache -dir so that the installation uses no cache whatsoever.
01:14 You run this and now you have to wait for a couple of seconds, which might be longer or shorter depending on your computer, network, etc. And when you’re done, you’ll see the output at the end telling you exactly how much time the command took to run, which was roughly 12.5 seconds for this recording.
01:35
Now you can do the same thing with uv. You’re going to initialize the uv project just so there’s something to install into. And now, you’re going to use time again to uv add jupyterlab and use the option --no-cache, so that uv uses no cache whatsoever while doing the installation.
01:57 You run this, you give it a couple of seconds, and then you get your results, which was 2.5 seconds for this run. So this is five times faster. 12.5 to 2.5 was five times faster on my computer for this recording.
02:14
So now we can see if there’s any timing differences when uninstalling packages. You’ll want to run the command time again. You’re going to use pip uninstall jupyterlab.
02:24
And now just make sure you don’t spend any time saying that yes, you want to uninstall, you just use the option -y so it’s immediate. You give it a second, it’s actually less than a second, and it removes everything in 0.4 seconds roughly.
02:37
And for uv, you can try a similar thing. You’re going to time uv remove jupyterlab and you give it a second. And it was actually slower than pip, which is kind of interesting.
02:50
But at the same time, if you look closely, note how there’s much more output on the uv side than there is on the side of pip. pip tells you that it uninstalled jupyterlab, whereas uv tells you that it uninstalls jupyterlab, but also all of the dependencies that you installed with it.
03:11
Because jupyterlab has a lot of dependencies, which means that to install jupyterlab, you need those dependencies. Now, when you are done with jupyterlab, uv sees all of these dependencies.
03:23
It finds the ones that you no longer need, and removes them as well. So you say that uv removes transitive dependencies, whereas pip only does literally what you told it to do.
03:35
You told pip to uninstall jupyterlab and that’s what it did. And if you check, you will still see a lot of dependencies installed in your virtual environment.
03:45
You didn’t install them directly. These were things that jupyterlab depended on and that stayed behind.
03:51
That’s why pip was so much faster, because it only removes one dependency and left a few dozen for you to clean up by yourself.
04:00
Now, the timings here. You use jupyterlab because it’s just a fairly common package. It’s non-trivial. It has a number of dependencies which allow you to see this behavior.
04:11 But of course, you can experiment with your own benchmarks, with your own packages to draw your own conclusions.
04:20
As you saw, uv tends to be quite faster than pip.
04:24
You also saw that uv will remove your transitive dependencies and leave you with a cleaner virtual environment, whereas pip does not do that.
04:33 So this can lead you to a couple of straightforward choices based on your priorities.
04:39
If you need fast installs, if you want to optimize the install time because maybe you are installing a lot of dependencies or a lot of dependencies repeatedly, then uv is your choice.
04:50
If not, you can keep on watching to learn more about the differences and similarities between pip and uv. And also, if getting rid of transitive dependencies is important for you, if you want to make sure that your virtual environments stay as clean as possible, then you’ll want to go with uv.
05:06
Otherwise, in the next lesson, you’re going to learn about reproducible installations and how uv and pip deal with those.
Become a Member to join the conversation.
