How to Use Miniconda for Isolated Python Environments
Miniconda gives you a clean way to create isolated Python environments for each project, which helps prevent package conflicts and makes your setups easier to reproduce.
MiniConda Series
environment.yml
How to save an environment cleanly and recreate it later on another machine or for another collaborator.
Read article
4
When to Use pip Inside a Conda Environment
Where pip fits into a Conda workflow and how to avoid careless mixing.
Read article
5
Common Conda Environment Mistakes and How to Avoid Them
The small habits that make environments harder to understand, harder to reproduce, and easier to break.
Read article
6
How to Remove Old Conda Environments Cleanly
A simple cleanup workflow for removing stale environments without losing reusable setup knowledge.
Read article
Different Python projects often need different package and Python versions.
Create one Conda environment per project.
Keep the base environment lean and avoid doing project work in it.
The Basic Workflow
- Create an environment for a project
- Activate it
- Install packages inside that environment
- Do your work
- Export the environment when you need to share or rebuild it
What Miniconda Is
Miniconda is a minimal Conda installation. It gives you Conda, Python, and a small set of core dependencies.
Unlike Anaconda, which installs a much larger package collection up front, Miniconda starts small and lets you install only what you actually need.
What a Conda Environment Is
A Conda environment is an isolated workspace for a project.
Each environment can have its own:
- Python version
- installed packages
- dependency graph
Project A
Python 3.10
numpy 1.26
Project B
Python 3.8
numpy 1.21
Both environments can exist on the same machine without stepping on each other.
Installing Miniconda
Installation steps vary a little by operating system and CPU architecture.
macOS (Intel)
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
bash Miniconda3-latest-MacOSX-x86_64.sh
macOS (Apple Silicon)
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh
bash Miniconda3-latest-MacOSX-arm64.sh
Linux
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
Windows
Download the installer for Windows and run it normally.
After installation, open a new terminal and verify Conda is working:
conda --version
A Typical Miniconda Workflow
conda create --name project1 python=3.10
conda activate project1
conda install numpy pandas
conda export --from-history --file environment.yml
That is the core pattern you will repeat for most projects.
Creating an Environment
It is a good habit to choose the Python version when you create an environment.
conda create --name myenv python=3.10
Example:
conda create --name data-analysis python=3.11
Activating and Deactivating Environments
Activate an environment:
conda activate myenv
Your shell prompt will usually change to show the active environment:
(base) user@computer % conda activate myenv
(myenv) user@computer %
Deactivate it with:
conda deactivate
Installing Packages
Install packages inside the active environment.
conda install numpy pandas matplotlib
Conda resolves dependencies for you, which is one reason it is useful for environment management.
If a package is not available through Conda
You can use pip inside the active environment:
pip install somepackage
Listing and Removing Environments
List environments:
conda env list
Remove an environment:
conda env remove --name myenv
Exporting and Recreating Environments
If you want to share an environment or rebuild it later, export it to a file.
Cleaner export for many projects
conda export --from-history --file environment.yml
This keeps the file more focused by recording what you explicitly asked Conda to install rather than every resolved package in the environment.
Another common export form
conda env export > environment.yml
This can be useful when you want a fuller snapshot of the environment.
Recreate the environment
conda env create -f environment.yml
Common Beginner Mistakes
Installing packages in base
The base environment is best kept lean. For real project dependencies, create a separate environment instead.
Forgetting to activate the environment
If the environment is not active, you may install packages somewhere you did not intend.
Mixing pip and Conda randomly
This is one of the fastest ways to make an environment harder to reproduce and harder to debug later.
Useful Commands
| Task | Command |
|---|---|
| Check Conda version | conda --version |
| Create environment | conda create --name myenv python=3.10 |
| Activate environment | conda activate myenv |
| Deactivate environment | conda deactivate |
| Install packages | conda install numpy pandas |
| List environments | conda env list |
| Export environment | conda export --from-history --file environment.yml |
| Recreate environment | conda env create -f environment.yml |
| Remove environment | conda env remove --name myenv |
conda create --name myenv python=3.10
conda activate myenv
conda install numpy pandas
conda export --from-history --file environment.yml
conda deactivate
Frequently Asked Questions
These are the practical questions that usually come up when starting with Miniconda and isolated Python environments.
What is the difference between Conda and Miniconda?
Conda is the package and environment manager. Miniconda is the small installer that gives you Conda, Python, and a minimal starting setup.
Is Miniconda better than Anaconda?
Miniconda is often the better choice when you want a smaller installation and tighter control over what gets installed.
Can Conda manage non-Python packages?
Yes. Conda can also manage some non-Python packages and dependencies, which is part of what makes it useful for reproducible environments.
Should I use pip or Conda?
Start with Conda. Use pip when the package you need is not available through Conda.
Why should I avoid doing project work in base?
Keeping base lean reduces the chance of package conflicts and makes it easier to reason about what belongs to each project.
What is the simplest habit that makes Conda easier to manage?
Create one environment per project, activate it before installing packages, and export it when you need to share or rebuild it later.
Conclusion
The Miniconda workflow is simple once you make it a habit.
Create one environment per project. Choose the Python version on purpose. Install packages inside the active environment. Export the environment when you need to share or rebuild it.
That small amount of structure goes a long way toward preventing dependency conflicts.
Raell Dottin
Comments
Post a Comment