User Guide: Managing Python with Conda (Miniconda)
Conda helps you manage Python versions and libraries for different projects by creating environments. Each environment is like a separate toolbox, keeping everything organized and conflict-free.
Why Use Conda? π€
- Separate Environments: Each project gets its own Python version and libraries.
- Avoid Conflicts: Project A needing
Library v1.0
won't break Project B needingLibrary v2.0
. - Rule #1: Always create a new environment for each project. Avoid installing project-specific tools in the default
(base)
environment.
Quick Start: Create Your First Environment π
Letβs create an environment for a web project using Flask.
- Open Your Terminal: Launch iTerm2.
- Create the Environment: Name it
flask_project
and use Python 3.11.conda create --name flask_project python=3.11
- Conda will list the packages it needs to install. Type
y
and press Enter.
- Conda will list the packages it needs to install. Type
- Activate the Environment: Step into your new environment.
conda activate flask_project
- Your prompt will now show
(flask_project)
, indicating the environment is active.
- Your prompt will now show
- Install Libraries: Use
pip
to install Flask.pip install Flask
- Work on Your Project: Create and run your Python files.
touch app.py python app.py
- Deactivate the Environment: Exit when you're done.
conda deactivate
Essential Conda Commands Cheat Sheet π
- List Environments:
conda env list
- Example Output:
base * /opt/homebrew/Caskroom/miniconda/base flask_project /opt/homebrew/Caskroom/miniconda/base/envs/flask_project
- Example Output:
- Create an Environment:
conda create --name <env_name> python=<version> # Example: conda create --name data_sci python=3.10
- Activate an Environment:
conda activate <env_name>
- Deactivate an Environment:
conda deactivate
- Install a Package:
conda install <package_name> # Example: conda install numpy pandas matplotlib
- Remove an Environment:
conda env remove --name <env_name>
- Export Environment to File:
conda env export > environment.yml
- Create Environment from File:
conda env create -f environment.yml
Conda makes managing Python projects simple and organized. Start creating environments and enjoy hassle-free development!