Python - UV

Table of Contents

As another tool for Python, uv is written by rust and provides integrated experience, e.g.

In Archlinux, uv can be easily installed by pacman, i.e.,

pacman -S uv

Its usage can be summarized as follows. Note that, if a virtual environment has already activated, then the argument --python /PATH/TO/ENVIRONMENT below can be omitted.

Python interpretor management

  • List the interpretors.

    uv python list
    
  • Install an interpretor.

    uv python install x.y[.z]
    

Virtual environment

  • Create a virtual environment based on the system interpretor.

    uv venv --python /usr/bin/python /PATH/TO/ENVIRONMENT
    
  • Create a virtual environment based on a specified interpretor.

    uv venv --python x.y[.z] /PATH/TO/ENVIRONMENT
    

Run a Python script or a function

uv run [--python /PATH/TO/ENVIRONMENT] SCRIPT.py

Package management

  • List the [outdated] packages installed.

    uv pip list [--outdated] [--python /PATH/TO/ENVIRONMENT]
    
  • List the details of a package.

    uv pip show [--python /PATH/TO/ENVIRONMENT] PACKAGE_NAME
    
  • Install a package.

    uv pip install [--python /PATH/TO/ENVIRONMENT] PACKAGE_NAME
    
  • Install packages from a list.

    uv pip install [--python /PATH/TO/ENVIRONMENT] -r requirements.txt
    
  • Upgrade a package.

    uv pip install [--python /PATH/TO/ENVIRONMENT] --upgrade PACKAGE_NAME
    
  • Update packages from a list.

    uv pip install [--python /PATH/TO/ENVIRONMENT] --upgrade -r requirements.txt
    
  • Remove a package.

    uv pip uninstall [--python /PATH/TO/ENVIRONMENT] PACKAGE_NAME
    
  • Export the list of installed packages.

    uv pip freeze [--python /PATH/TO/ENVIRONMENT] > requirements.txt
    

Mirror configuration

A mirror site can be configured in ~/.config/uv/uv.toml or /etc/uv/uv.toml.

[[index]]
url = "https://mirrors.aliyun.com/pypi/simple"
default = true