From 25733ecad8a57c138368c9c8ab1091c6e94277f9 Mon Sep 17 00:00:00 2001 From: tiyn Date: Tue, 14 Jul 2026 02:22:38 +0200 Subject: [PATCH] Python: Created Own uv Entry --- wiki/linux/package_manager.md | 8 ++- wiki/programming_language/python.md | 58 ++++-------------- wiki/programming_language/python/uv.md | 82 ++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 49 deletions(-) create mode 100644 wiki/programming_language/python/uv.md diff --git a/wiki/linux/package_manager.md b/wiki/linux/package_manager.md index 4c73d32..d96b054 100644 --- a/wiki/linux/package_manager.md +++ b/wiki/linux/package_manager.md @@ -20,5 +20,9 @@ across distributions. These formats are not package managers. They distribute standalone applications that can run independently of the system package database. -- [AppImage](/wiki/linux/appimage.md) -- [Flatpak](/wiki/linux/flatpak.md) +- [AppImage](/wiki/linux/appimage.md) packages applications together with their dependencies in a + single executable file. +- [Flatpak](/wiki/linux/flatpak.md) distributes sandboxed desktop applications across different + Linux distributions. +- [uv](/wiki/programming_language/python/uv.md) manages Python installations, virtual environments, + project dependencies and Python-based command-line tools. diff --git a/wiki/programming_language/python.md b/wiki/programming_language/python.md index 8e5805b..bc19d81 100644 --- a/wiki/programming_language/python.md +++ b/wiki/programming_language/python.md @@ -11,24 +11,9 @@ You can install python using various ways. Using various [package managers](/wiki/linux/package_manager.md) the current python version can be easily installed. -Additionally, a [pyenv](#pyenv-installation), [uv](#uv-installation) or +Additionally, a [pyenv](#pyenv-installation), [uv](/wiki/programming_language/python/uv.md) or [manual installation](#manual-installation) can be done to get a specific older version for projects. -### uv Installation - -[uv](https://docs.astral.sh/uv/) is a python package and project manager. -It can manage python versions. - -Versions can be installed and set for the current directory and subdirectories as shown in the -following commands where `` is the python version. - -```sh -uv python install -uv python pin -``` - -uv can also be used to manage [virtual environments](#uv-virtual-environments). - ### pyenv Installation With [pyenv](https://github.com/pyenv/pyenv) you can easily switch between different versions. @@ -141,35 +126,8 @@ to it and run `pipreqs` (install it if not already done). There are various options to use virtual environments. The first and most commonly used option is [venv](#venv-virtual-environments). -A more modern and arguably better approach is using [uv](#uv-virtual-environments). - -#### uv Virtual Environments - -Since uv is a project-based tool the following command has to be used to create a project where -`` is the path to the project directory. -If it is omitted the project will be created in the current working directory. - -```sh -uv init -``` - -Additionally, this command can be expanded with flags. -To create the most basic form of a project without a `README.md` the `--bare` flag can be used. - -To use uv as a virtual environment similar to venv the following command can be invoked inside a -project directory. -It will create a `.venv` directory containing the `bin/activate` file. - -```sh -uv venv -``` - -Packages can then be installed using the following command. -`` is the name of the package to install. - -```sh -uv add -``` +A more modern and arguably better approach is using +[uv](/wiki/programming_language/python/uv.md#virtual-environments). #### venv Virtual Environments @@ -218,10 +176,16 @@ Alternatively local package manager like the [ones of various Linux distributions](/wiki/linux/package_manager.md) can sometimes be used to install packages globally. Due to different package versions (especially on rolling release distributions) this can fail. -If it doesnt work the packages can be installed globally using `pip` together with the +If it doesn't work the packages can be installed globally using `pip` together with the `--break-system-packages` flag. This flag is to be used with care. +A generally more favourable approach is to install modules using +[virtual environments](#using-virtual-environments). +This, however, is only practical for projects although some virtual environment package managers +such as [uv](/wiki/programming_language/python/uv.md) can also handle global installation of Python +pacakges. + This section addresses various different modules. ### scikit-learn @@ -240,7 +204,7 @@ As explained in the [cuml guide on zero code change acceleration](https://docs.rapids.ai/api/cuml/latest/cuml-accel/) only the following two lines have to be added to run the scikit-learn algorithms on the GPU. Additionally, cuml has to be installed using a [Python package manager](#using-virtual-environments) -like [uv](#uv-virtual-environments). +like [uv](/wiki/programming_language/python/uv.md#installing-packages). It is important that these lines are put before importing any scikit-learn packages. ```py diff --git a/wiki/programming_language/python/uv.md b/wiki/programming_language/python/uv.md new file mode 100644 index 0000000..197c480 --- /dev/null +++ b/wiki/programming_language/python/uv.md @@ -0,0 +1,82 @@ +# uv + +[uv](https://docs.astral.sh/uv/) is a fast [Python](/wiki/programming_language/python.md) package, +project and version manager. +It can install and manage Python versions, create virtual environments and manage project +dependencies. + +## Setup + +Refer to the [official installation guide](https://docs.astral.sh/uv/getting-started/installation/) +to install `uv` on your operating system. + +## Usage + +This section addresses the usage of uv. + +### Managing Python Versions + +Python versions can be installed and pinned for the current project by replacing +`` with the desired version. + +```sh +uv python install +uv python pin +``` + +### Creating a Project + +A new project can be created by replacing `` with the desired project +directory. +If omitted, the project will be created in the current working directory. + +```sh +uv init +``` + +To create a minimal project without a `README.md`, use the `--bare` option. + +### Virtual Environments + +Inside a project directory, create a virtual environment with: + +```sh +uv venv +``` + +This creates a `.venv` directory containing the virtual environment. + +### Installing Packages + +Packages can be added to the current project by replacing `` with the +desired package. + +```sh +uv add +``` + +### Installing CLI Tools + +Besides managing projects and virtual environments, `uv` can also install +[Python-based](/wiki/programming_language/python.md) command-line tools globally. +Each tool is installed into its own isolated environment while remaining available from the command +line. + +Install a tool by replacing `` with its name. + +```sh +uv tool install +``` + +Installed tools remain available independently of any project or virtual environment. + +Project dependencies, however, should be managed inside the corresponding project using commands +such as the following. + +```sh +uv add +uv sync +``` + +This separation avoids dependency conflicts between globally installed command- line tools and +project-specific Python packages.