Jump to content

User:Ranjithsiji/Flask with uv

From Wikitech

This is a small guide about how to use uv as a packagemanager for python projects in toolforge.

uv package manager

  • uv source page
  • A single tool to replace pip, pip-tools, pipx, poetry, pyenv, twine, virtualenv, and more.
  • 10-100x faster than pip.
  • Provides comprehensive project management, with a universal lockfile.

Install uv

Our setup is now

~/www/python/src

To install uv just use the code

$ webservice python3.13 shell
$ curl -LsSf https://astral.sh/uv/install.sh | sh
downloading uv 0.11.7 x86_64-unknown-linux-gnu
installing to /data/project/your-project-name/.local/bin
  uv
  uvx
everything's installed!
To add $HOME/.local/bin to your PATH, either restart your shell or run:

Now exit from the shell and start the shell again to get the uv command in the shell

venv diretory

The default python virtualenv directory in toolforge is at /data/project/your-project-name/www/venv. But uv will create the virtual environment in .venv. So need a command

webservice python3.13 shell
uv venv /data/project/your-project-name/www/python/venv

To get an active path in python shell use this variable

export UV_PROJECT_ENVIRONMENT="/data/project/your-project-name/.local/bin/env"

Activate the venv with python shell. The uv sync with the project. The pyproject.toml contains the packages and its versions.

source /data/project/your-project-name/www/python/venv/bin/activate
cd  /data/project/your-project-name/www/python/src
uv sync --active