Python dependencies & packaging for Django in production
Installing exactly the right packages everywhere: lock files, uv, Poetry, pip-tools, and upgrades.
Pinned dependencies make every install identical, from a laptop to CI to production. Without them, a release can change behaviour without a single line of your code changing.
The guides cover pip-tools with hashes, uv, Poetry, psycopg installation, and keeping dependencies updated without surprises.
Set it up
Guides that take this from nothing to running in production.
- Deploy Django with uv for Reproducible Installs
Deploy Django reproducibly with uv: lockfiles, uv sync --locked without dev tools, managed Python, Docker layer caching, and CI checks.
- Deploy Django with Poetry
Deploy a Poetry-managed Django project: lock file checks, installing only main dependencies, in-project virtualenvs, multi-stage Docker builds without Poetry at runtime, and exporting requirements.
- Pin Django Dependencies with pip-tools and Hashes
Make Django installs reproducible and tamper-resistant with pip-tools: requirements.in, compiled pins with hashes, separate dev requirements, pip install --require-hashes, and safe upgrades.
- uv vs Poetry vs pip for Django Deployments
Compare uv, Poetry, and pip with pip-tools for managing Django dependencies in production: lock files, install speed in CI and Docker, reproducibility with hashes, Python version management, and migration paths between them.
Run it well
Tuning, reliability, and operations once it works.
- Automate Django Dependency and Security Updates
Keep Django and its dependencies current safely: Dependabot or Renovate, pip-audit in CI, grouped updates, test gates, and urgent security releases.
- Upgrade the Python Version of a Production Django App
Upgrade a production Django app to a newer Python version safely: check Django and dependency support, run tests on both versions in CI, rebuild virtualenvs or images, upgrade Celery workers together, deploy gradually, and roll back cleanly.
Check it
Review lists to run before launch or after a change.
- Django Version Upgrade Checklist for Production
Upgrade Django in production safely: plan the target version, read release notes, fix deprecations, upgrade dependencies, test, deploy, and roll back if needed.
- Django Dependency Security Checklist
Secure the software supply chain of a Django app: supported Django versions, pinned and hashed dependencies, vulnerability scanning, private index safety, container image updates, CI action pinning, and SBOMs.
Fix it
Errors and symptoms, each traced to a cause and a fix.
- Fix ModuleNotFoundError When Starting Django with Gunicorn
Fix ModuleNotFoundError when Gunicorn starts Django: wrong virtualenv, working directory, project module path, missing packages, and Python version mismatches.
- Fix psycopg Installation Errors on Django Servers
Fix psycopg and psycopg2 install failures on servers and Docker images: pg_config not found, missing libpq, binary versus source builds, and missing wheels.
- Fix pip "externally-managed-environment" on a Django Server
Fix pip error externally-managed-environment on Ubuntu 24.04, Debian 12, and other PEP 668 systems when installing Django: create a virtualenv or use uv, use pipx for tools, and avoid --break-system-packages on servers.
- Fix a Broken Django Virtualenv After an OS Upgrade
Fix a Django virtualenv that breaks after upgrading Ubuntu or Debian or changing the Python version: errors like No module named encodings and bad interpreter, recreating the venv safely, and avoiding downtime during the switch.
- Fix Django ImportError After Upgrading: force_text, ugettext, url() and Others
Fix ImportError cannot import name force_text, smart_text, ugettext_lazy, url, or ifequal after a Django upgrade: map each removed API to its replacement, upgrade third-party packages that still use them, and catch removals in CI before deploying.
- Fix mysqlclient Install Errors (mysql_config not found)
Fix pip install mysqlclient failures for Django: mysql_config not found, pkg-config cannot find mysqlclient, and missing Python.h, on Ubuntu, Debian, RHEL, Alpine, macOS, and in Docker builds.
- Fix Pillow Errors on Django Image Uploads in Production
Fix Pillow errors when uploading images to Django in production: Cannot use ImageField because Pillow is not installed, decoder jpeg not available, cannot identify image file, DecompressionBombError, and HEIC uploads.
- Fix Django models.W042 Auto-Created Primary Key Warning
Fix the Django models.W042 warning about auto-created primary keys: choose between AutoField and BigAutoField for DEFAULT_AUTO_FIELD, avoid surprise migrations on large tables, handle third-party apps, and prepare for the BigAutoField default in Django 6.0.
- Fix pip "Temporary Failure in Name Resolution" During Docker Builds
Fix pip install failing during a Django Docker build with Temporary failure in name resolution or Failed to establish a new connection: diagnose Docker DNS, corporate proxies, VPNs, and IPv6, and configure daemon DNS or build-time proxy arguments.
- Why Django Docker Builds Fail on Alpine, and How to Fix Them
Fix Django Docker builds that fail or crawl on python:alpine: understand musl and missing wheels, install the right build packages for psycopg, Pillow, and cryptography, or switch to python:slim for faster, smaller, more reliable images.
- Fix Heroku "Failed to Compile Python App" for Django
Fix Heroku push rejected, failed to compile Python app for Django: set the Python version with .python-version, fix requirements and lock files, resolve packages that need system libraries, and clear a stale build cache.
- Fix WeasyPrint "Cannot Load Library" for Django PDF Generation in Docker
Fix WeasyPrint OSError cannot load library gobject-2.0-0, libpango, or libharfbuzz when generating PDFs in Django on Docker, Heroku, or a slim server: install Pango and fonts, use the right package names, and keep PDF rendering in a worker.