Skip to content
Back to home

Flexible Python Environment Management with Conda and uv

Table of Contents

Open Table of Contents

Background

Python projects vary widely, from data analysis and machine learning to web development and small utility scripts. Each type has different requirements for Python versions, environment isolation, and dependency management. Simple projects might only need pip for dependencies, but as projects scale or complexity increases, issues like version conflicts and environment bloat emerge.

For example, data science projects often rely on large machine learning libraries (like TensorFlow or PyTorch) requiring stable isolation, while web development or lightweight scripts prioritize lightweight, fast dependency management and flexible Python version switching. Traditional conda is powerful but environments can be several GB, making it cumbersome. Based on this, I’ve optimized the environment management approach, using a combination of Conda and uv to replace the previous conda-pyenv-poetry setup for more efficient, lightweight Python environment management.

My goals are:

Conda

Conda is an open-source package and environment management system originally designed for Python data science projects, but now supports multiple programming languages (like R, Node.js, Java, etc.). Developed by Anaconda, it’s widely used in data science, machine learning, and scientific computing.

Installation and Configuration

Recommend using Miniforge, a lightweight Conda distribution tailored for the conda-forge channel with preset features:

Configuration Optimization:

# Disable automatic activation of base environment to avoid interfering with other Python environments
conda config --set auto_activate_base false

# Verify Conda installation:
conda --version
mamba --version

Note: On Windows, ensure Conda’s PATH priority is lower than uv’s Python paths to avoid version conflicts. Adjust the order in system PATH, placing uv’s path before Conda.

uv

uv is a modern Python package manager written in Rust, integrating Python version management, virtual environment creation, and dependency management, far outperforming tools like Pyenv and Poetry. Its core advantages include:

Installation and Setup

Install UV:

Configure UV:


This work is licensed under “CC BY-NC-SA 4.0”. For commercial use, please contact the site owner for authorization. For non-commercial sharing, please keep attribution and the original link. If you remix, transform, or build upon this material, you must distribute your contributions under the same license.

Share this post on:

Previous Post
2024 Work Summary
Next Post
Repost | The Normality and Abnormality of Chinese