Skip to Content
DokumentationEntwicklungLokale KI / Datenwissenschaft

Lokale KI-/Data-Science-Umgebung

Dieser Artikel beschreibt, wie Sie eine vollständige lokale KI- und Data-Science-Entwicklungsumgebung auf Ubuntu 26.04 erstellen.

NVIDIA CUDA Umgebungseinrichtung

Das Ausführen GPU-beschleunigter KI-Modelle erfordert zunächst die Installation der NVIDIA-Treiber und des CUDA-Toolkits.

NVIDIA-Treiber installieren

# Check the recommended driver version ubuntu-drivers devices # Install the recommended driver sudo ubuntu-drivers autoinstall # Or manually install the version reported by ubuntu-drivers devices sudo apt install nvidia-driver-XXX -y # Reboot sudo reboot

Treiber überprüfen:

nvidia-smi

CUDA-Toolkit installieren

# Install via apt (Ubuntu repository version) sudo apt install cuda-toolkit -y # Verify nvcc --version

Für eine bestimmte CUDA-Version installieren Sie aus dem offiziellen Repository von NVIDIA (Ubuntu 26.04 verwendet ubuntu2604):

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2604/x86_64/cuda-keyring_1.1-1_all.deb sudo dpkg -i cuda-keyring_1.1-1_all.deb sudo apt update # List available CUDA Toolkit versions in the repository apt-cache search cuda-toolkit # Install a specific version (replace XX-Y with an actual available version) sudo apt install cuda-toolkit-XX-Y -y
Note

Ubuntu 26.04 liefert jetzt das NVIDIA CUDA Toolkit in seinen offiziellen Repositories, sodass sudo apt install cuda-toolkit direkt funktioniert. Das ubuntu2604-Repository von NVIDIA bleibt nützlich, wenn Sie eine bestimmte CUDA-Version benötigen.

Umgebungsvariablen konfigurieren:

echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc source ~/.bashrc

cuDNN installieren

sudo apt install libcudnn9-cuda-12 libcudnn9-dev-cuda-12 -y

Ollama: Große Sprachmodelle lokal ausführen

Mit Ollama können Sie große Sprachmodelle wie Llama, Mistral und Gemma einfach lokal ausführen.

Ollama installieren

curl -fsSL https://ollama.com/install.sh | sh

Grundlegende Nutzung

# Run a model (downloads automatically on first use) ollama run llama3.2 # Run other models ollama run mistral ollama run gemma2 ollama run qwen2.5 ollama run deepseek-r1 # List downloaded models ollama list # Delete a model ollama rm llama3.2 # View running models ollama ps

Ollama API

Ollama bietet eine REST-API, die standardmäßig unter http://localhost:11434 läuft:

# Generate text curl http://localhost:11434/api/generate -d '{ "model": "llama3.2", "prompt": "Explain what machine learning is" }' # Chat conversation curl http://localhost:11434/api/chat -d '{ "model": "llama3.2", "messages": [ {"role": "user", "content": "Hello"} ] }'

Verwendung mit Open WebUI

Open WebUI bietet eine ChatGPT-ähnliche Weboberfläche für Ollama:

docker run -d -p 3000:8080 \ --add-host=host.docker.internal:host-gateway \ -v open-webui:/app/backend/data \ --name open-webui \ ghcr.io/open-webui/open-webui:main

Zugriff darauf unter http://localhost:3000.

Jupyter Notebook / Lab

Jupyter ist die beliebteste interaktive Entwicklungsumgebung für Data Science und maschinelles Lernen.

JupyterLab installieren

# Ubuntu 26.04 blocks system-wide pip installs (PEP 668) # Method 1: install as a standalone app with pipx sudo apt install -y pipx pipx ensurepath pipx install jupyterlab # Method 2: install inside a virtual environment python3 -m venv ~/jupyter-env source ~/jupyter-env/bin/activate pip install jupyterlab notebook # Method 3: use conda conda install -c conda-forge jupyterlab

JupyterLab starten

jupyter lab

Ihr Browser öffnet http://localhost:8888 automatisch.

Gängige Kernel installieren

# Install R kernel sudo apt install r-base -y R -e "install.packages('IRkernel'); IRkernel::installspec()" # Install a kernel for a specific virtual environment python -m ipykernel install --user --name myenv --display-name "Python (myenv)"

Empfohlene Jupyter-Erweiterungen

# Install in the same virtual environment as JupyterLab (or inject via pipx) # pipx users can run: pipx inject jupyterlab jupyterlab-lsp python-lsp-server jupyterlab-git pip install jupyterlab-lsp python-lsp-server pip install jupyterlab-git

PyTorch

PyTorch ist derzeit das beliebteste Deep-Learning-Framework.

PyTorch installieren (GPU)

# Install inside a virtual environment (PEP 668) python3 -m venv ~/torch-env source ~/torch-env/bin/activate # pip install torch installs the wheel for the current CUDA by default; # older drivers can pin a lower CUDA, e.g. cu126 pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126 # Using conda conda install pytorch torchvision torchaudio pytorch-cuda=12.6 -c pytorch -c nvidia

PyTorch installieren (CPU)

pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu

GPU-Unterstützung von PyTorch überprüfen

import torch print(f"PyTorch version: {torch.__version__}") print(f"CUDA available: {torch.cuda.is_available()}") print(f"CUDA version: {torch.version.cuda}") print(f"GPU device: {torch.cuda.get_device_name(0)}") # Simple test x = torch.rand(3, 3).cuda() print(x)

TensorFlow

TensorFlow installieren

# Create a venv first (PEP 668: system Python rejects pip installs) python3 -m venv ~/tf-env && source ~/tf-env/bin/activate # GPU version (auto-detects CUDA) pip install tensorflow # Verify python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

GPU-Überprüfung für TensorFlow

import tensorflow as tf print(f"TensorFlow version: {tf.__version__}") print(f"GPU devices: {tf.config.list_physical_devices('GPU')}") # Simple test with tf.device('/GPU:0'): a = tf.constant([[1.0, 2.0], [3.0, 4.0]]) b = tf.constant([[5.0, 6.0], [7.0, 8.0]]) c = tf.matmul(a, b) print(c)

Gängige Data-Science-Pakete

# Activate a virtual environment first (PEP 668: no pip into the system Python) python3 -m venv ~/ds-env && source ~/ds-env/bin/activate pip install numpy pandas matplotlib seaborn scikit-learn scipy pip install plotly bokeh altair pip install polars # High-performance alternative to pandas pip install xgboost lightgbm catboost # Gradient boosting frameworks

Beispiel für eine vollständige KI-Entwicklungsumgebung

Hier ist ein empfohlener Workflow zum Einrichten einer Projektumgebung:

# Create project directory mkdir ~/ai-project && cd ~/ai-project # Create conda environment (pip is safe inside a conda environment) conda create -n ai python=3.13 -y conda activate ai # Install core libraries (current CUDA by default; older drivers can pin cu126) pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126 pip install transformers datasets accelerate pip install jupyterlab pip install numpy pandas matplotlib scikit-learn # Launch Jupyter jupyter lab

Hugging Face Transformers verwenden

pip install transformers datasets accelerate
from transformers import pipeline # Text generation generator = pipeline("text-generation", model="gpt2") result = generator("The future of artificial intelligence is", max_length=50) print(result) # Sentiment analysis classifier = pipeline("sentiment-analysis") result = classifier("This product is amazing") print(result)

GPU-Auslastung überwachen

# Real-time monitoring watch -n 1 nvidia-smi # Use nvitop (more visually appealing) -- install as a standalone CLI with pipx pipx install nvitop nvitop # Use gpustat pipx install gpustat gpustat -i 1

Nachdem Ihre lokale KI-Umgebung eingerichtet ist, können Sie verschiedene große Sprachmodelle und Deep-Learning-Aufgaben auf Ubuntu 26.04 ausführen.

Last updated on