conda vs poetry vs uv vs pip
After spending a year troubleshooting and researching Python packaging tools and installers, I've put together this guide to share some best practices for managing Python environments and packages. By leveraging the strengths of conda, poetry, uv, and pip, you can create efficient workflows for both development and deployment.
Local Development
- Use Conda to Create Environments
- Conda is great for isolating environments on the same machine.
- Create an environment:
conda create -n local_env python=3.14(creates an empty environment with Python 3.14). - Activate an environment:
conda activate local_env.- Example:
(local_env) user - $- you are now in thelocal_envenvironment.
- Example:
- Use Poetry to Manage Packages
- Poetry works with
pyproject.tomlto add and install packages. - Example:
poetry add numpyto add a package. - This process creates a
poetry.lockfile that manages dependency resolution. - Keep using
poetry add <package>to add packages. - Note: Poetry creates its own virtual environment, but it isn't used directly unless
poetry runis invoked. This doesn't affect us since we're interested in package resolution. - Once ready, install the packages using
pip install .or
pip install -e .wherepoetry.lockandpyproject.tomlare located. - This installs all packages into the current Conda environment (
local_env). - You can repeat this process for other environments, making it easy to switch between projects (e.g.,
dev_envandprod_env).
- Poetry works with
CI / DevOps / Docker Builds
- No Need for Conda
- At this stage, we assume
poetry.lockhas all required packages resolved. - Use Poetry to Set Up Environments
poetry.lockandpyproject.tomlare key for dependency management.- Use
poetry installto install packages andpoetry runto execute anything. - Poetry creates a local virtual environment (
venv) that's only invoked withpoetry run. - Alternatively,
poetry shellcan be used to activate the environment temporarily, though this is not recommended for production use.
- Poetry Install Speed
- Despite improvements,
poetry installcan still be slow (although it is 10x faster thanpip installand 20x faster thanconda install).
- Despite improvements,
- At this stage, we assume
- Use
uvfor Fast Installationsuvis a Rust-based package installer, and it's much faster.- Requires
requirements.txt, which can be generated by Poetry:poetry export --without-hashes -f requirements.txt- This takes less than 1 second to generate.
- Run the following command to install dependencies:
uv pip install --no-deps -r <(poetry export --without-hashes -f requirements.txt)
uvusespipunder the hood and creates a virtual environment much faster than Poetry.- After using
uv, runpoetry installto update the Poetry source tree. - This allows you to use Poetry for a seamless developer experience while leveraging
uvfor fast installations.
- Fastest Installation Method
- For production environments, you can combine commands for speed:
uv pip install --no-deps -r <(poetry export --without-hashes --with dev -f requirements.txt)- Then update with:
poetry install --only-root
- For production environments, you can combine commands for speed:
Summary (TL;DR)
If Developing Locally/Natively
- Use Conda to create environments.
- Use Poetry to resolve and install packages.
- Use Pip for installing packages or editable packages.
Everywhere Else (Production)
- Use
poetry.lockandpyproject.tomlto craft your environment (10x faster than Conda). - Use
uvto install dependencies (10x faster thanpoetry install, 30x faster thanconda install). - Use Poetry to run or execute scripts (no Conda environment needed).
- Optionally,
uv runalso exists.
Conclusion
The approach taken here shows an ambition to achieve a finely-tuned workflow that combines speed, reliability, and consistency. However, the layered complexity of combining conda, poetry, pip, and uv in this way could present a learning curve that not all teams are prepared to tackle. Many teams may find this setup over-engineered for their needs, especially if they do not require the minute optimizations that uv provides.