Guides Long read Paket Yonetimi

How do you manage dependencies?

Isolated, reliable environments with pip, venv, and Poetry.

12 January 2026 17 min read
Share
X in

Introduction

Python's ecosystem strength comes from thousands of packages on PyPI, but dependency management grows complex as projects scale. Running pip install directly into system Python leads to version conflicts and 'works on my machine' problems. Virtual environments and lock file discipline are fundamentals of professional development.

This article compares isolation with venv, installation with pip, freezing with requirements.txt, and modern project management with Poetry. The goal is a reproducible dependency graph in CI/CD pipelines and Docker images.

Virtual Environments with venv

python -m venv .venv creates an isolated interpreter and site-packages folder in the project directory. On Windows use .venv\Scripts\activate; on Unix use source .venv/bin/activate. Deactivate returns to system Python.

Use a separate venv per project to avoid polluting global site-packages. Add .venv to .gitignore; the environment is machine-specific. Creating a fresh venv on every CI build is standard practice.

python -m venv .venv
# Windows:
.venv\Scripts\activate
# Linux/macOS:
source .venv/bin/activate
pip install --upgrade pip

pip and Dependency Files

pip install requests downloads and installs the package into the active environment. pip freeze > requirements.txt pins everything in the current environment; pip install -r requirements.txt reinstalls the same set. freeze may include dev tools; prefer a separate requirements-prod.txt for production.

pip-tools (pip-compile) generates a resolved requirements.txt from requirements.in; transitive dependencies are pinned. pip install package==1.2.3 locks versions; choose semver upper bounds (^, ~=) carefully.

  • pip install -r requirements.txt: bulk install
  • pip freeze: freeze current environment
  • pip-compile: generate resolved dependencies
  • pip list --outdated: check for updates

Modern Project Management with Poetry

Poetry consolidates project metadata, dependencies, and build settings in pyproject.toml. poetry add requests adds a runtime dependency; poetry add --group dev pytest adds to the dev group. poetry.lock locks the full resolution and must be committed.

poetry install installs from the lock file; poetry update upgrades selected packages. poetry build and poetry publish release to PyPI. PEP 621 compliant pyproject.toml continues to replace setuptools and setup.py.

poetry new myproject
cd myproject
poetry add fastapi uvicorn
poetry add --group dev pytest ruff
poetry install
poetry run pytest

venv + pip vs Poetry

venv + pip + requirements.txt is minimal and works everywhere with no extra tools. Poetry combines dependency resolution, virtual environment management, and publishing. venv is enough for small scripts; libraries and multi-module apps favor Poetry or pipenv.

Newer tools like uv and rye are pip-compatible but much faster. Pick a team standard and stay consistent across repos; mixing pip/poetry/conda raises onboarding cost.

Docker and CI Integration

In Dockerfile use multi-stage builds: copy requirements first and pip install, then add application code to leverage layer cache. For Poetry use poetry export -f requirements.txt or poetry install --only main.

In GitHub Actions pin Python with actions/setup-python; speed downloads with cache: pip or cache: poetry. Add pip-audit or a poetry audit plugin for security scanning in the pipeline.

  1. Pin Python version with .python-version or matrix
  2. Commit the lock file
  3. Separate production and development dependencies
  4. Run regular security scans

Common Issues

ModuleNotFoundError usually means wrong environment or missing install; verify the active interpreter with which python. Version conflicts surface as pip resolver errors; inspect the graph with poetry show --tree or pipdeptree.

Missing platform-specific wheels require source builds; add build-essential and python3-dev to the Docker image. For private PyPI use pip.conf or POETRY_HTTP_BASIC_* environment variables.

Do not deploy to production without a lock file; reproducibility is lost.

Conclusion

Solid package management is a prerequisite for scalable Python projects. Isolate with venv, lock dependencies with pip or Poetry, and install the same graph in CI. Poetry is a strong default for modern projects; venv + pip-tools suffices for minimal needs.

Plan dependency updates regularly; validate major version bumps in a test environment. Keeping setup docs current saves new developers hours on day one.