mirror of
https://github.com/tiyn/wiki.git
synced 2026-07-26 12:21:35 +02:00
Python: Created Own uv Entry
This commit is contained in:
@@ -20,5 +20,9 @@ across distributions.
|
|||||||
These formats are not package managers.
|
These formats are not package managers.
|
||||||
They distribute standalone applications that can run independently of the system package database.
|
They distribute standalone applications that can run independently of the system package database.
|
||||||
|
|
||||||
- [AppImage](/wiki/linux/appimage.md)
|
- [AppImage](/wiki/linux/appimage.md) packages applications together with their dependencies in a
|
||||||
- [Flatpak](/wiki/linux/flatpak.md)
|
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.
|
||||||
|
|||||||
@@ -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
|
Using various [package managers](/wiki/linux/package_manager.md) the current python version can be
|
||||||
easily installed.
|
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.
|
[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 `<python-version>` is the python version.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
uv python install <python-version>
|
|
||||||
uv python pin <python-version>
|
|
||||||
```
|
|
||||||
|
|
||||||
uv can also be used to manage [virtual environments](#uv-virtual-environments).
|
|
||||||
|
|
||||||
### pyenv Installation
|
### pyenv Installation
|
||||||
|
|
||||||
With [pyenv](https://github.com/pyenv/pyenv) you can easily switch between different versions.
|
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.
|
There are various options to use virtual environments.
|
||||||
The first and most commonly used option is [venv](#venv-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).
|
A more modern and arguably better approach is using
|
||||||
|
[uv](/wiki/programming_language/python/uv.md#virtual-environments).
|
||||||
#### uv Virtual Environments
|
|
||||||
|
|
||||||
Since uv is a project-based tool the following command has to be used to create a project where
|
|
||||||
`<path>` is the path to the project directory.
|
|
||||||
If it is omitted the project will be created in the current working directory.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
uv init <path>
|
|
||||||
```
|
|
||||||
|
|
||||||
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.
|
|
||||||
`<package>` is the name of the package to install.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
uv add <package>
|
|
||||||
```
|
|
||||||
|
|
||||||
#### venv 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
|
[ones of various Linux distributions](/wiki/linux/package_manager.md) can sometimes be used to
|
||||||
install packages globally.
|
install packages globally.
|
||||||
Due to different package versions (especially on rolling release distributions) this can fail.
|
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.
|
`--break-system-packages` flag.
|
||||||
This flag is to be used with care.
|
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.
|
This section addresses various different modules.
|
||||||
|
|
||||||
### scikit-learn
|
### 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/)
|
[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.
|
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)
|
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.
|
It is important that these lines are put before importing any scikit-learn packages.
|
||||||
|
|
||||||
```py
|
```py
|
||||||
|
|||||||
82
wiki/programming_language/python/uv.md
Normal file
82
wiki/programming_language/python/uv.md
Normal file
@@ -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
|
||||||
|
`<python-version>` with the desired version.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
uv python install <python-version>
|
||||||
|
uv python pin <python-version>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Creating a Project
|
||||||
|
|
||||||
|
A new project can be created by replacing `<path>` with the desired project
|
||||||
|
directory.
|
||||||
|
If omitted, the project will be created in the current working directory.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
uv init <path>
|
||||||
|
```
|
||||||
|
|
||||||
|
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 `<package>` with the
|
||||||
|
desired package.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
uv add <package>
|
||||||
|
```
|
||||||
|
|
||||||
|
### 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 `<package>` with its name.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
uv tool install <package>
|
||||||
|
```
|
||||||
|
|
||||||
|
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 <package>
|
||||||
|
uv sync
|
||||||
|
```
|
||||||
|
|
||||||
|
This separation avoids dependency conflicts between globally installed command- line tools and
|
||||||
|
project-specific Python packages.
|
||||||
Reference in New Issue
Block a user