Conda is a powerful open-source package and environment management system that simplifies working with different programming languages, especially Python. With Conda, you can create isolated environments—self-contained directories that contain specific versions of packages and dependencies. This ensures that your projects remain organized, reproducible, and free from conflicts between different software requirements.
In simple words, you can create a conda environment to isolate your python packages without conflicting with other conda environments. It gives you this flexibility to run code in ease independent from other conda envs. It can also be used by PyCharm.
Why Use Conda Environments?
- Isolation: Avoid version clashes between projects by keeping dependencies separate.
- Reproducibility: Share your environment configuration so others can replicate your setup. This means that by creating a basic script file, you can easily reproduce a conda env through command prompt.
- Flexibility: Easily switch between different Python versions and packages. (Conda activate Env1, Conda activate Env2, etc. It is literally that Easy!)
- Cross-Platform: Works seamlessly on Windows, macOS, and Linux (Doesn’t matter that much if you stick to linux like me).
Whether you’re a data scientist, developer, or researcher, mastering Conda environments will help you manage your workflows efficiently. Let’s explore how to create, use, and manage Conda environments effectively!
How to Install Conda
There are two main distributions of Conda:
- Anaconda – A full-featured distribution that includes Conda, Python, and many pre-installed scientific packages (good for beginners).
- Miniconda – A lightweight version that includes only Conda and Python (better for advanced users who want minimal setup).
Installation Steps
1. Download Conda (Anaconda or Miniconda)
- Anaconda: Download from Anaconda’s official site
- Miniconda: Download from Miniconda’s official site (Personally I prefer this option).
Choose the installer for your operating system (Windows, macOS, or Linux).
2. Run the Installer
Windows
- Double-click the downloaded
.exe
file. - Follow the setup wizard (recommended: check “Add Anaconda to PATH” during installation).
- Open Anaconda Prompt (or restart your terminal).
macOS / Linux
- Open a terminal and navigate to the download directory.
- Run the installer (replace
filename.sh
with your downloaded file):
bash filename.sh
- Follow the prompts (press
Enter
to confirm defaults). - Restart your terminal or run:
source ~/.bashrc # or ~/.zshrc (for macOS/Linux)
3. Verify Installation
Check if Conda is installed correctly:
conda --version
You should see something like:
conda 24.1.2
To see all available commands:
conda --help
4. Update Conda (Optional but Recommended)
Ensure you have the latest version:
conda update conda
Next Steps
Now that Conda is installed, you can:
✅ Create a new environment:
conda create --name my_env python=3.9
✅ Activate it:
conda activate my_env
✅ Install packages:
conda install numpy pandas matplotlib
Difference between Conda and Docker
Docker is a platform for developing, shipping, and running applications in lightweight, portable containers. Unlike traditional virtual machines, Docker containers virtualize the operating system (OS) level, allowing apps to run in isolated environments with their own dependencies, libraries, and configurations—without needing a full OS for each instance. Containers share the host OS kernel, making them faster, more efficient, and easier to deploy across different environments (e.g., local machines, cloud servers). Docker simplifies software delivery by ensuring consistency from development to production, enabling tools like microservices, CI/CD pipelines, and scalable cloud deployments.
When to Use Which?
Use Conda if you need:
✅ Isolated Python environments (e.g., different projects require different package versions).
✅ Easy package management for data science (NumPy, Pandas, TensorFlow).
✅ A lightweight solution without full OS virtualization.
Use Docker if you need:
✅ Complete environment reproducibility (including OS-level dependencies).
✅ Running applications in isolated containers (e.g., web servers, databases).
✅ Cross-platform deployment (same container runs on Windows, Linux, macOS).
Can They Work Together?
The answer is Yes! they can.
- Use Conda inside a Docker container to manage Python dependencies.
- Example: A Dockerized Jupyter Lab with Conda environments for data science.
Example: Using Conda to Manage a Python Data Science Environment
Let’s walk through a practical example of using Conda to:
- Create a new environment
- Install packages (e.g., NumPy, Pandas, Jupyter)
- Activate & use the environment
- Export & share the environment
Step 1: Create a Conda Environment
conda create --name my_data_science_env python=3.10
- This creates a new environment named
my_data_science_env
with Python 3.10.
Step 2: Activate the Environment
conda activate my_data_science_env
- Your terminal prompt should now show
(my_data_science_env)
.
Step 3: Install Packages
Install commonly used data science libraries:
conda install numpy pandas matplotlib scikit-learn jupyter
- Conda resolves dependencies automatically.
Step 4: Launch Jupyter Notebook (Optional)
jupyter notebook
- This opens Jupyter in your browser, where you can write Python code using the installed packages.
Step 5: Deactivate the Environment
When you’re done:
conda deactivate
Step 6: Export the Environment (For Sharing/Reproducibility)
conda env export > environment.yml
- This creates an
environment.yml
file that others can use to recreate the same environment.
To recreate the environment from environment.yml
:
conda env create -f environment.yml
Key Conda Commands Cheat Sheet
Command | Description |
---|---|
conda create --name my_env python=3.9 | Create a new environment |
conda activate my_env | Activate the environment |
conda install numpy pandas | Install packages |
conda list | List installed packages |
conda deactivate | Exit the environment |
conda env export > environment.yml | Save environment to a file |
conda env remove --name my_env | Delete an environment |
Why This Workflow is Useful
✔ No conflicts – Different projects can use different package versions.
✔ Reproducible – Share environment.yml
for consistent setups.
✔ Clean & organized – Avoids global Python package clutter.