Hybrid Project Management with uv and Conda
Managing scientific projects often requires balancing system-level dependencies (GDAL, PROJ, HDF5) with Python package reproducibility. Conda and uv serve complementary roles:
-
Conda excels at installing compiled libraries and cross-language dependencies.
-
uv provides fast, modern dependency resolution and reproducible lockfiles for Python packages.
Why Hybrid?
-
Geospatial and climate libraries (e.g., GDAL, rasterio) are best installed via Conda-forge.
-
Python-only packages (numpy, pandas, scikit-learn) are faster and more reproducible with uv.
-
Combining both ensures stability and speed.
Workflow Template
- Create Conda Environment
conda create -n hydro-env python=3.11 gdal proj
or
conda env create -f environment.yml
Activate the new environment:
conda activate hydro-env
pip install uv
or
conda install conda-forge::uv
simply, installing uv with the virtual environment creating.
conda create -n hydro-env -c conda-forge python=3.11 gdal proj uv
- Initialize uv Project
Navigating into the project directory, and initializing it:
uv init
uv add numpy pandas rasterio
This creates pyproject.toml and uv.lock inside the project, aligned with Conda’s Python. Or synchronizing the environment when setting up on a new machine with uv.lock
uv sync
uv sync possibly upgrade newer versions of dependencies and updates uv.lock. For a production or research cases to guarantee reproducibility and prevent accidental upgrades, using:
uv sync --frozen
It will read uv.lock only and enforce exact versions.
- Run Scripts
uv run script.py
This ensures dependencies from uv.lock are resolved while Conda provides system libraries.
- Jupyter Integration
uv add jupyter
then:
uv run jupyter notebook or uv run jupyter lab
Best Practices
-
Keep
environment.ymlfor Conda (system deps). -
Keep
pyproject.toml+uv.lockfor uv (Python deps). -
Document both so collaborators can choose Conda or uv depending on their workflow.
-
Align
.python-versionwith Conda’s Python to avoid mismatches.
Conclusion
The hybrid approach leverages Conda’s strength in compiled libraries and uv’s speed in Python dependency management. For geo-related projects, this ensures reproducibility, portability, and efficiency across diverse research teams.
Related commands
- Export the Conda environment to a YAML file using this command:
conda env export > environment.yml
- Check the available Jupyter kernels:
uv run jupyter kernelspec list
-
Remove a virtual environment managed by uv, simply delete the directory
.venv. -
Remove a Conda environment:
conda deactivate
conda env remove --name hydro-env
References
Working on projects - uv Astral Docs
Python tools