SoFunction
Updated on 2025-05-08

python uv basic usage tutorial

The following isuvTutorial for use.uvis a super fast Python package installation tool and parser developed by Astral, written in Rust, designed to replacepippip-toolsandvirtualenv, provides faster performance and better dependency management.

1. Install uv

It can be installed in any of the following waysuv

1.1 Install using pip (recommended)

pip install uv

1.2 Download the binary file directly

Download precompiled binary files from GitHub Releases:
/astral-sh/uv/releases

2. Basic use

2.1 Creating a virtual environment

# Create a virtual environment named `venv` (default directory)uv venv
# Specify the virtual environment name or pathuv venv myenv

2.2 Activate the virtual environment

Linux/macOS:

source myenv/bin/activate

Windows (PowerShell):

.\myenv\Scripts\activate

2.3 Installing dependency packages

# Install a single packageuv pip install requests
# Install multiple packagesuv pip install requests pandas
# Install fromuv pip install -r 

2.4 Generate

# Export the dependencies of the current environment touv pip freeze > 

2.5 Upgrade dependencies

# Upgrade the specified packageuv pip install --upgrade requests
# Upgrade all packagesuv pip install --upgrade -r 

2.6 Uninstall the package

uv pip uninstall requests

3. Advanced usage

3.1 Quickly initialize the project

# Initialize the project and install the dependencies (complete in one step)uv venv && uv pip install -r 

3.2 Production environment deployment

use--systemInstall directly in Python system (not recommended, it is recommended to use a virtual environment):

uv pip install --system -r 

3.3 Dependency resolution and locking

uvSupports generation of precise dependency lock files (similar topoetry):

# Generate lock fileuv pip compile  -o 

3.4 Replace pip command

uvFully compatiblepipCommands can be replaced directly:

# For example:uv pip list
uv pip show requests

4. Performance Advantages

  • Speedy installationuvInstallation speed ratiopip10-100 times faster.
  • Concurrent download: Supports parallel download of dependency packages.
  • Better dependency analysis:avoidpipdependency conflict problem.

5. Frequently Asked Questions

5.1 How to migrate existing projects to uv?

  • Delete old virtual environments (e.g.venv)。
  • useuv venvCreate a new environment.
  • runuv pip install -r

5.2 Compatibility with pip?

uvFully compatiblepipCommands andFormat, no need to modify existing configurations.

5.3 Which operating systems are supported?

LinuxmacOSWindows (PowerShell required)

6. Official Resources

GitHub repository: /astral-sh/uv documentation:

passuv, you can significantly improve the efficiency of Python dependency management. Try to replace traditionalpipandvirtualenv, experience a faster development process!

This is the end of this article about the tutorial on using python uv. For more related content on using python uv, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!