-
Notifications
You must be signed in to change notification settings - Fork 0
TEMPLATE PyProject
Felix Staacke edited this page Feb 25, 2026
·
3 revisions
Minimal
pyproject.tomlfür neue Python-Projekte
Vollständige Erklärung: Pythonprojekt Standards
- Ordnerstruktur (src-layout)
- Minimal
pyproject.toml - Setup & Verwendung
- Migration von requirements.txt
- Häufige Anpassungen
- Troubleshooting
project-name/
├── src/
│ └── your_package/
│ ├── __init__.py
│ ├── main.py
│ └── ...
├── tests/
├── pyproject.toml # ← Dieses Template
├── README.md
└── .gitignore
# === Build System ===========================
[build-system]
requires = ["setuptools>=68"]
build-backend = "setuptools.build_meta"
# === Project Metadata ====================
[project]
name = "your-project"
version = "0.1.0"
description = "Kurze Projektbeschreibung"
readme = "README.md"
requires-python = ">=3.10"
license = { text = "MIT" }
authors = [
{ name = "Vorname Nachname", email = "email@example.org" }
]
# === Dependencies ========================
dependencies = [
# Core packages
"requests>=2.31",
"pandas>=2.0",
# Git Submodules (Development)
# "gta @ git+https://github.com/HisQu/GTA.git@main",
# Git Submodules (Production - mit commit hash)
# "gta @ git+https://github.com/HisQu/GTA.git@abc123def",
]
# === Optional Dependencies ===============
# Requires pip ≥ 25.1, update with `python -m pip install --upgrade pip`
[dependency-groups]
dev = [
"pytest>=8",
"black>=24",
"ruff>=0.5",
"mypy>=1.10",
]
# === Package Discovery ===================
[tool.setuptools.packages.find]
where = ["src"]
include = ["*"]# 1. Virtual environment erstellen
python -m venv .venv
source .venv/bin/activate # Linux/macOS
# .venv\Scripts\activate # Windows
# 2. Editable install (Entwicklung)
pip install -e ".[dev]"
# 3. Projekt ausführen
python -m your_package.main# Alt:
pip install -r requirements.txt
pip install -r dev-requirements.txt
# Neu:
pip install -e ".[dev]"Migrationsschritte:
- Pakete aus
requirements.txt→[project.dependencies] - Dev-Pakete →
[dependency-groups.dev] - Code nach
src/your_package/verschieben -
__init__.pyerstellen
# Nur für Webapps:
[project]
dependencies = [
"fastapi>=0.115",
"uvicorn[standard]>=0.30",
]
# CLI Tools:
[project.scripts]
mytool = "your_package.cli:main"
# Zusätzliche Dateien einschließen:
[tool.setuptools.package-data]
"your_package" = ["data/*.json", "templates/*.html"]| Problem | Lösung |
|---|---|
ModuleNotFoundError |
__init__.py in src/your_package/ erstellen |
| Paket nicht gefunden |
where = ["src"] in [tool.setuptools.packages.find] prüfen |
| Import funktioniert nicht |
from your_package import ... statt from . import ...
|
| Git Submodule SSH-Fehler | SSH-Key für GitHub konfigurieren oder HTTPS verwenden |