What is Python's virtual environment and dependency management?
Answer
Python dependency management has evolved significantly. pip is the standard package installer. requirements.txt pins dependencies: pip freeze > requirements.txt, install with pip install -r requirements.txt. Poetry is the modern standard: manages dependencies (pyproject.toml), lock file (poetry.lock), virtual env, and building/publishing. Commands: poetry add requests, poetry install, poetry run python app.py. Pipenv combines pip and venv with Pipfile and Pipfile.lock. conda manages both Python packages and non-Python dependencies — popular in data science. pyproject.toml (PEP 518) is the modern standard for project metadata, replacing setup.py. Use pip-tools for reproducible builds: compile requirements with version pinning. Virtual environments isolate project dependencies, preventing conflicts between projects.
Previous
What is Python's requests library?
Next
What is Python's context managers and the contextlib module?