Difference between uv, uvx and pip
1. Purpose
This post aims to introduce the Python dependency management tools uv
, uvx
, and pip
. I’ll explain their usage and key differences.
2. Environment
- macos System
3. What is the difference between the uv
,uvx
and pip
?
pip
is the most widely used package installer in the Python community, while uv
and uvx
, developed by Astral, are designed to offer a faster and more reliable alternative. Understanding what sets them apart is key to choosing the right tool for your needs.
Here is the diagram show their differences:
What is pip?
pip
is the standard package management system for Python. It’s what you use to install and manage software packages, which are most often found on the Python Package Index (PyPI). pip
is a comprehensive tool that supports managing project dependencies via requirements.txt
files and is the foundational and most common tool in the Python ecosystem.
pip
is the most widely used package installer for Python.
-
Install a package:
Terminal window pip install requestsThis command installs the latest version of the
requests
library from PyPI. -
Install a specific version:
Terminal window pip install flask==2.2.2This installs version 2.2.2 of the
flask
library. -
Install from a
requirements.txt
file:Terminal window pip install -r requirements.txtThis is a very common way to install all dependencies listed in a
requirements.txt
file. -
Upgrade a package:
Terminal window pip install --upgrade numpyThis upgrades the
numpy
package to the latest available version. -
Uninstall a package:
Terminal window pip uninstall requestsThis command removes the
requests
library from your environment. You will typically be prompted to confirm. -
List installed packages:
Terminal window pip listShows all installed packages and their versions in the current environment.
-
List installed packages in
requirements.txt
format:Terminal window pip freezeOutputs the list of installed packages and their exact versions in a format suitable for
requirements.txt
.
What is uv
?
uv
is a high-performance Python package installer and resolver written in Rust
. It’s built to be a drop-in replacement for common pip
and pip-tools
workflows. uv
is laser-focused on speed and reliability, offering features like dependency resolution, locking, installation, and virtual environment management. Its ambitious goal is to become the “Cargo for Python” (Cargo being Rust’s build tool and package manager).
Here are some examples of using uv
:
-
Create a virtual environment:
Terminal window uv venvThis creates a new virtual environment in a
.venv
directory in your current location. -
Activate a virtual environment (Linux/macOS):
Terminal window source .venv/bin/activate -
Activate a virtual environment (Windows):
Terminal window .venv\Scripts\activate -
Install a package:
Terminal window uv pip install requestsSimilar to
pip install
, but typically much faster. -
Install from a
requirements.txt
file:Terminal window uv pip install -r requirements.txtInstalls dependencies from a
requirements.txt
file usinguv
’s speed. -
Compile a
requirements.txt
file (likepip-compile
):Terminal window uv pip compile requirements.in -o requirements.txtReads dependencies from
requirements.in
and generates a lockedrequirements.txt
with exact versions. -
Sync an environment with a locked
requirements.txt
(likepip-sync
):Terminal window uv pip sync requirements.txtInstalls or uninstalls packages to match the exact versions in the
requirements.txt
file. -
Add a dependency to a project (requires
pyproject.toml
):Terminal window uv add flaskAdds
flask
to yourpyproject.toml
and automatically syncs your environment and updates theuv.lock
file. -
Run a command in the project environment (requires
pyproject.toml
):Terminal window uv run python your_script.pyRuns
your_script.py
within the project’s virtual environment without explicit activation.
What is uvx?
uvx
is part of the uv
toolchain, specifically an alias for the uv tool run
command. The primary purpose of uvx
is to execute Python tools or scripts in a temporary, isolated environment without needing to install them globally or activate a virtual environment first. This is incredibly handy for running tools like linters (e.g., ruff), formatters (e.g., black), or other command-line utilities, ensuring you use a specific version each time without cluttering your global environment.
uvx
is a convenient alias for uv tool run
. It’s designed for running Python tools in isolated, temporary environments.
-
Run a tool (e.g., ruff) without installing it globally:
Terminal window uvx ruff check your_module.pyuvx
will find or installruff
in a temporary environment, run thecheck
command onyour_module.py
, and then clean up the environment (though it caches the tool for faster subsequent runs). -
Run a specific version of a tool:
Terminal window Executes the
black
formatter version 23.7.0 onyour_script.py
. -
Run a tool with extra dependencies:
Terminal window uvx --with 'mypy[extra]' mypy your_module.pyRuns
mypy
with itsextra
dependencies installed in the temporary environment. -
Run a tool from a specific package name (if different from the command):
Terminal window uvx --from httpie http example.comRuns the
http
command, which is provided by thehttpie
package.
The difference
Feature | pip | uv | uvx |
---|---|---|---|
Core Function | Install, uninstall, upgrade, list packages | Install, resolve, lock packages; manage virtual environments | Run tools/scripts in a temporary environment |
Performance | Relatively slower, especially with complex dependencies | Extremely fast due to Rust implementation | Fast startup and execution, no pre-installation needed |
Dependency Resolution | Improved resolver in newer versions, but conflict handling can be unclear | Highly optimized, clear errors, better conflict resolution | Resolves and installs dependencies in a temporary environment |
Virtual Environments | Requires separate tools like venv or virtualenv to create/activate | Built-in virtual environment management, auto-creation | Runs in a temporary virtual environment, auto-managed |
Lock Files | Needs tools like pip-tools for requirements.txt | Supports generating cross-platform lock files (uv.lock ) | Uses temporary environments, explicit lock files usually not needed |
Tool Execution | Requires global installation or activated environment | Can be used for project dependencies, uv run for project commands | Directly runs specified tools/scripts and their deps, no install needed |
Ease of Use | Widely adopted, extensive documentation | Intuitive CLI, some commands compatible with pip | Simple command for running one-off tools |
Installation | Usually comes with Python | Installable via standalone script or pip itself | Installed as part of uv |
As the table shows, pip
serves as a fundamental and versatile package manager. uv
extends this by offering enhanced performance and features for a more modern dependency management experience. uvx
, on the other hand, streamlines the process of running standalone tools by providing a convenient “one-off” execution environment.
uv
is designed to be a unified replacement for pip
and related tools (like pip-tools
and virtualenv
), aiming for faster performance and a more consistent user experience. uvx
builds on uv
, further simplifying the execution of individual tools.
4. Summary
In this post, I explained the differences between the uv
,uvx
and pip
commands in Linux. Choosing the right tool ultimately depends on your project’s specific needs and your personal preferences. For most existing projects and scenarios where extreme performance isn’t the top priority, pip
remains a reliable choice. For new projects or situations requiring frequent handling of complex dependencies and rapid environment setup, uv
is likely a better fit. And uvx
is a handy helper for quickly running tools you don’t need installed long-term.
Final Words + More Resources
My intention with this article was to help others who might be considering solving such a problem. So I hope that’s been the case here. If you still have any questions, don’t hesitate to ask me by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!