Conda Environment Management Guide
This tutorial will guide you through installing and configuring Conda, and learning how to use it to manage Python environments and package dependencies.
Conda Overview
What is Conda?
Conda is an open-source package management and environment management system, mainly used for managing Python packages but also supporting other languages. It can:
- Create isolated Python environments
- Manage package dependencies
- Easily switch between environments required by different projects
- Resolve package version conflicts
Why Choose Conda?
- Environment isolation: Each project can have an independent Python environment
- Dependency management: Automatically resolves package dependency conflicts
- Cross-platform: Supports Windows, macOS, and Linux
- Rich packages: Includes packages for scientific computing, machine learning, and other fields
- Easy to use: Command-line operations are simple and intuitive
Installing Conda
Choosing an Installation Version
Conda is a lightweight package management and environment management system. We recommend installing Miniconda:
- Small size: About 400 MB
- Included content: Conda + Python + base packages
- Advantages: Fast installation, and you can install specific packages as needed
Downloading Conda
Download Miniconda
- Visit the Conda official download page
- Select the Miniconda column
- Choose the version suitable for your system:
- Linux:
Miniconda3-latest-Linux-x86_64.sh - macOS Intel:
Miniconda3-latest-MacOSX-x86_64.sh - macOS Apple Silicon (M1/M2/M3):
Miniconda3-latest-MacOSX-arm64.sh - Windows:
Miniconda3-latest-Windows-x86_64.exe
- Linux:
Installing Conda
Linux Installation
# Download the installation script
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
# Or use curl
curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
# Run the installation script
bash Miniconda3-latest-Linux-x86_64.sh
# Follow the prompts to complete the installation
# 1. Read the license agreement and type 'yes' to agree
# 2. Choose the installation path (the default is fine)
# 3. Choose whether to initialize conda (recommended to choose 'yes')
macOS Installation
Method 1: GUI installation (recommended)
Use the uname -m command in the command line to find out your architecture version
- Download the
.pkgfile for your version - Follow the installation wizard to complete the installation
- Select Add Miniconda3 to my PATH environment variable (recommended)
Method 2: Command-line installation
If you choose the command-line installation method, you need to download the installation script first:
# Intel chip Mac - download the installation script
curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
# Apple Silicon (M1/M2/M3) Mac - download the installation script
curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh
# Run the installation script
bash Miniconda3-latest-MacOSX-x86_64.sh # Intel chip
# Or
bash Miniconda3-latest-MacOSX-arm64.sh # Apple Silicon
# Follow the prompts to complete the installation
# 1. Read the license agreement and type 'yes' to agree
# 2. Choose the installation path (the default is fine)
# 3. Choose whether to initialize conda (recommended to choose 'yes')
Configuring environment variables (important step on macOS)
After installation, you need to add Conda to the system PATH:
# For Zsh users (macOS Catalina and above use Zsh by default)
echo 'export PATH="$HOME/miniconda3/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
# For Bash users
echo 'export PATH="$HOME/miniconda3/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
Windows Installation
- Double-click the downloaded
.exefile - Follow the installation wizard to complete the installation
- Select Add Miniconda3 to my PATH environment variable (recommended)
- Select Register Miniconda3 as my default Python 3.x
Verifying the Installation
After installation, reopen the terminal and verify:
# Check the conda version
conda --version
# Check conda info
conda info
# Check the Python version
python --version
Conda Basic Usage
1. Environment Management
Creating a New Environment
Synria Robotics' SDK and example code are all validated based on Python ≥ 3.11. Please do not use versions lower than 3.11. The examples below uniformly use python=3.11.
# Create an environment with a specified Python version (change "myenv" as you like)
conda create --name myenv python=3.11
# Create an environment and install packages
conda create --name myenv python=3.11 numpy pandas
Activating/Deactivating an Environment
# Activate the environment
conda activate myenv
# Deactivate the environment
conda deactivate
# List all environments
conda env list
# Or
conda info --envs
Deleting an Environment
# Delete the environment
conda env remove --name myenv
# Confirm deletion
conda env remove --name myenv --yes
2. Package Management
Installing Packages
# Install a single package
conda install numpy
# Install multiple packages
conda install numpy pandas matplotlib
# Install a specific version
conda install numpy=1.21.0
# Install from a specific channel
conda install -c conda-forge opencv
Viewing and Managing Packages
# List installed packages
conda list
# View information about a specific package
conda list numpy
# Update a package
conda update numpy
# Update all packages
conda update --all
# Uninstall a package
conda remove numpy