UV voor virtuele omgevingen

Op deze pagina:

Hoe gebruik je uv met Python voor het beheren van virtuele omgevingen?

Met uv kun je eenvoudig virtuele omgevingen beheren in Python.

Installeren van uv

Je kunt uv installeren via verschillende methoden, bijvoorbeeld:

Linux/macOS:


curl -LsSf https://astral.sh/uv/install.sh | sh

Dit gaf:


curl -LsSf https://astral.sh/uv/install.sh | sh
downloading uv 0.7.12 x86_64-unknown-linux-gnu
no checksums to verify
installing to /home/kees/.local/bin
  uv
  uvx
everything's installed!

macOS via Homebrew:


brew install uv

Windows:


powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

Met pip:


pip install uv

Dit laatste werkte niet in OpenSUSE Tumleweed:


pip install uv
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try
    zypper install python313-xyz, where xyz is the package
    you are trying to install.

    If you wish to install a non-rpm packaged Python package,
    create a virtual environment using python3.13 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip.

    If you wish to install a non-rpm packaged Python application,
    it may be easiest to use `pipx install xyz`, which will manage a
    virtual environment for you. Install pipx via `zypper install python313-pipx` .

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

Virtuele omgeving maken

Om een virtuele omgeving te maken, gebruik je:


uv venv

Resultaat:


uv venv
Using CPython 3.13.3 interpreter at: /usr/bin/python3
Creating virtual environment at: .venv
Activate with: source .venv/bin/activate

Virtuele omgeving activeren

macOS/Linux:


source .venv/bin/activate

Pakketten installeren binnen de virtuele omgeving


uv pip install markdown
Resolved 1 package in 56ms
Prepared 1 package in 12ms
Installed 1 package in 6ms
 + markdown==3.8

Virtuele omgeving deactiveren


deactivate

 

Verwante artikelen