_
_
_
Pipenv Cheatsheet¶
• Installation
Umgebungsvariablen¶
# Virtualenv location
export PIPENV_VENV_IN_PROJECT=1 # Create .venv in project
export WORKON_HOME=~/.virtualenvs # Custom virtualenv location
# Timeout settings
export PIPENV_TIMEOUT=300 # Lock timeout (seconds)
export PIPENV_INSTALL_TIMEOUT=900 # Install timeout
# Behavior settings
export PIPENV_SKIP_LOCK=1 # Skip lock generation
export PIPENV_NOSPIN=1 # Disable spinner (for CI)
export PIPENV_HIDE_EMOJIS=1 # Disable emojis (for CI)
export PIPENV_YES=1 # Auto-yes to prompts
# Python version
export PIPENV_PYTHON=3.11 # Default Python version
# Custom PyPI mirror
export PIPENV_PYPI_MIRROR=https://pypi.org/simple
.env Dateiunterstützung¶
Pipenv lädt automatisch .env Datei in Projektwurzel:
Häufige Anwendungsfälle
Use Case: Neues Django-Projekt starten¶
# Initialize project with Python 3.11
pipenv --python 3.11
# Install Django and production dependencies
pipenv install django psycopg2-binary gunicorn
# Install development tools
pipenv install pytest pytest-django black --dev
# Activate environment and start project
pipenv shell
django-admin startproject myproject .
Use Case: Bereitstellung zur Produktion¶
# On development machine - lock dependencies
pipenv lock
# Commit Pipfile and Pipfile.lock to version control
git add Pipfile Pipfile.lock
git commit -m "Lock dependencies"
# On production server - install exact versions
pipenv sync
# Run application
pipenv run gunicorn myapp.wsgi:application
Use Case: Arbeiten mit Teammitgliedern¶
# Clone repository
git clone https://github.com/team/project.git
cd project
# Install all dependencies (including dev)
pipenv install --dev
# Activate environment
pipenv shell
# Run tests
pytest
# When adding new package, lock and commit
pipenv install new-package
git add Pipfile Pipfile.lock
git commit -m "Add new-package dependency"
Use Case: CI/CD Pipeline¶
# In CI configuration (e.g., .gitlab-ci.yml, GitHub Actions)
# Install pipenv
pip install pipenv
# Install dependencies without dev packages
pipenv sync
# Run tests
pipenv run pytest
# Check for security vulnerabilities
pipenv check
# Set CI-friendly environment variables
export PIPENV_NOSPIN=1
export PIPENV_HIDE_EMOJIS=1
Use Case: Mehrere Umgebungen verwalten¶
# Development environment
pipenv install --dev
pipenv run python manage.py runserver
# Testing environment
pipenv sync --dev
pipenv run pytest
# Production environment
pipenv sync # Only production dependencies
pipenv run gunicorn app:app
# Staging with specific configuration
pipenv run --env-file=.env.staging python app.py
oder Best Practices
- ** verpflichtet immer sowohl Pipfile als auch Pipfile.lock* zur Versionskontrolle für reproduzierbare Builds über Umgebungen
- Use
pipenv syncin der Produktion anstelle vonpipenv install_, um genaue Versionen von Pipfile zu gewährleisten. Schloss installiert - Separate dev und Produktionsabhängigkeiten mit
--devFlagge, um Produktionsumgebungen schlank zu halten - Run
pipenv check_ regelmäßig um Sicherheitslücken in Ihren Abhängigkeiten zu scannen - **Diese Versionszwänge sinnvoll nutzen* -
~=_ für kompatible Versionen,>=,<für Reichweiten,==nur bei Bedarf **Create virtualenv im Projektverzeichnis* durch EinstellungPIPENV_VENV_IN_PROJECT=1für eine einfachere IDE-Integration - Use
pipenv runfür Ein-Aus-Befehle statt Shell zu aktivieren, wenn Skripte in der Automatisierung ausgeführt werden - Gemeinsame Skripte in Pipfile unter
[scripts]Sektion für Teamkonsistenz - **Keep Pipfile.lock aktualisiert* durch Laufen __INLINE_CODE_71_ nach Änderung Pipfile manuell
- Use
.envDateien für die umgebungsspezifische Konfiguration - Pipenv lädt sie automatisch
Fehlerbehebung
| Issue | Solution |
|---|---|
| INLINE_CODE_73 | Add INLINE_CODE_74 to PATH or reinstall with INLINE_CODE_75 |
| Lock operation takes too long | Increase timeout: INLINE_CODE_76 or use INLINE_CODE_77 for faster installs |
| Dependency resolution conflicts | Try INLINE_CODE_78 to regenerate lock file from scratch |
| Virtual environment not activating | Check INLINE_CODE_79 shows path, try INLINE_CODE_80 and recreate with INLINE_CODE_81 |
| Package not found in Pipfile.lock | Run INLINE_CODE_82 to regenerate lock file with new dependencies |
| Wrong Python version used | Specify version explicitly: INLINE_CODE_83 or check INLINE_CODE_84 in Pipfile |
| SSL certificate verification errors | Set INLINE_CODE_85 in Pipfile INLINE_CODE_86 section (not recommended for production) |
| Pipenv installs system-wide packages | Ensure INLINE_CODE_87 is not set, or unset it |
| Can't find locally installed package | Install in editable mode: INLINE_CODE_88 |
| INLINE_CODE_89 fails in CI | Use INLINE_CODE_90 to ignore specific known issues |
| Slow package installation | Use a PyPI mirror: INLINE_CODE_91 |
| Conflicting lock file on team | Ensure all team members use same Python version specified in INLINE_CODE_92 |
 Versionsspezifikationen Schnelle Referenz
| Specifier | Meaning | Example |
|---|---|---|
| INLINE_CODE_93 | Any version | INLINE_CODE_94 |
| INLINE_CODE_95 | Exact version | INLINE_CODE_96 |
| INLINE_CODE_97 | Greater than or equal | INLINE_CODE_98 |
| INLINE_CODE_99 | Less than or equal | INLINE_CODE_100 |
| INLINE_CODE_101 | Compatible release | INLINE_CODE_102 (>=2.28.0, <2.29.0) |
| INLINE_CODE_103 | Version range | INLINE_CODE_104 |
| _ | != |