Zum Inhalt

_

_

_

Pipenv Cheatsheet

• Installation

Platform Command
Ubuntu/Debian INLINE_CODE_9 or INLINE_CODE_10
Fedora/RHEL INLINE_CODE_11 or INLINE_CODE_12
Arch Linux INLINE_CODE_13
macOS INLINE_CODE_14 or INLINE_CODE_15
Windows INLINE_CODE_16 or INLINE_CODE_17
Verify Installation INLINE_CODE_18
_
**Post-Installation (bei Verwendung von --user): **
# Linux/macOS - Add to PATH
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
```_

oder Grundlegende Befehle

| Command | Description |
|---------|-------------|
| __INLINE_CODE_19__ | Create new project with Python 3 |
| __INLINE_CODE_20__ | Create project with specific Python version |
| __INLINE_CODE_21__ | Install all dependencies from Pipfile |
| __INLINE_CODE_22__ | Install a package and add to Pipfile |
| __INLINE_CODE_23__ | Install package as dev dependency |
| __INLINE_CODE_24__ | Install from requirements.txt file |
| __INLINE_CODE_25__ | Remove a package |
| __INLINE_CODE_26__ | Remove all packages |
| __INLINE_CODE_27__ | Activate virtual environment |
| __INLINE_CODE_28__ | Deactivate virtual environment (inside shell) |
| __INLINE_CODE_29__ | Run command without activating shell |
| __INLINE_CODE_30__ | Show virtualenv path |
| __INLINE_CODE_31__ | Show project directory path |
| __INLINE_CODE_32__ | Show Python interpreter path |
| __INLINE_CODE_33__ | Remove virtual environment |
| __INLINE_CODE_34__ | Generate/update Pipfile.lock |
| __INLINE_CODE_35__ | Install from Pipfile.lock (production) |
| __INLINE_CODE_36__ | Update all packages to latest versions |
| __INLINE_CODE_37__ | List installed packages |
| __INLINE_CODE_38__ | Show dependency tree |
| __INLINE_CODE_39__ | Check for security vulnerabilities |
_
/ Fortgeschrittene Nutzung

| Command | Description |
|---------|-------------|
| __INLINE_CODE_40__ | Install with version constraints |
| __INLINE_CODE_41__ | Install local package in editable mode |
| __INLINE_CODE_42__ | Install from Git repository |
| __INLINE_CODE_43__ | Install package with extras |
| __INLINE_CODE_44__ | Install without updating lock file (faster) |
| __INLINE_CODE_45__ | Sync including dev dependencies |
| __INLINE_CODE_46__ | Remove packages not in Pipfile.lock |
| __INLINE_CODE_47__ | Clear and regenerate lock file |
| __INLINE_CODE_48__ | Lock including pre-release versions |
| __INLINE_CODE_49__ | Update specific package only |
| __INLINE_CODE_50__ | Show outdated packages |
| __INLINE_CODE_51__ | Show reverse dependency tree |
| __INLINE_CODE_52__ | Output dependency graph as JSON |
| __INLINE_CODE_53__ | Detailed security vulnerability check |
| __INLINE_CODE_54__ | Export to requirements.txt format |
| __INLINE_CODE_55__ | Export dev requirements |
| __INLINE_CODE_56__ | Run script defined in Pipfile |
| __INLINE_CODE_57__ | Create .venv in project directory |
| __INLINE_CODE_58__ | Use specific Python executable |
| __INLINE_CODE_59__ | Lock without updating existing packages |
_
Konfiguration

### Pipfile Structure

```toml
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
django = ">=4.0,<5.0"
requests = "~=2.28.0"
psycopg2-binary = "*"
celery = {extras = ["redis"], version = ">=5.0"}
mypackage = {editable = true, path = "."}
private-pkg = {git = "ssh://git@github.com/user/repo.git", ref = "main"}

[dev-packages]
pytest = "*"
black = "==23.1.0"
flake8 = "*"
mypy = "*"

[requires]
python_version = "3.11"

[scripts]
start = "python manage.py runserver"
test = "pytest tests/ -v"
lint = "flake8 src/"
format = "black src/"

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:

# .env file example
DATABASE_URL=postgresql://localhost/mydb
SECRET_KEY=your-secret-key
DEBUG=True

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 sync in der Produktion anstelle von pipenv install_, um genaue Versionen von Pipfile zu gewährleisten. Schloss installiert
  • Separate dev und Produktionsabhängigkeiten mit --dev Flagge, 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 Einstellung PIPENV_VENV_IN_PROJECT=1 für eine einfachere IDE-Integration
  • Use pipenv run fü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 .env Dateien 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
_ !=