Create and Manage Conda Environments for Python Projects
Conda environments isolate Python dependencies for different projects. Create with 'conda create -n envname python=3.9', activate with 'conda activate envname', and export with 'conda env export > environment.yml' for reproducibility.
26 Oct 2025, 06:43 UTC

Problem: Dependency Conflicts Across Projects
When multiple Python projects require different package versions or Python releases, installing dependencies globally leads to conflicts that break existing functionality. You need isolated workspaces where each project maintains its own dependency tree without interference.
Prerequisites
- Anaconda or Miniconda installed and accessible from your terminal
- Basic familiarity with command-line operations
- Administrative privileges if installing packages system-wide
Procedure
- Verify conda installation
conda --version
Expected output:
conda 23.x.xor similar version number. - Create a new environment
conda create -n myproject python=3.9
This creates an isolated environment named
myprojectwith Python 3.9. Conda resolves and downloads all necessary dependencies automatically.Important: Environment names with spaces must be quoted:
conda create -n 'my project' python=3.9 - Activate the environment
conda activate myproject
Your prompt should now show
(myproject)prefix, indicating the environment is active. - Install project dependencies
conda install numpy pandas scikit-learn
Install packages within the active environment. They remain isolated from other environments and the base environment.
- List all environments
conda env list
Shows all created environments with an asterisk (*) marking the currently active one.
- Deactivate when finished
conda deactivate
Returns you to the base environment.
- Export environment for sharing
conda env export > environment.yml
Creates a reproducible specification file containing exact package versions and build numbers.
- Remove environment when no longer needed
conda env remove -n myproject
Frees disk space by deleting the environment completely.
Expected Checks
- After
conda activate myproject, verify withpython --versionshowing the correct Python release - Confirm isolation by installing a package in one environment and checking it doesn't appear in another
- Validate environment.yml by examining it contains
name: myprojectand dependency list
Recovery Options
- If environment activation fails, run
conda init bash(or your shell) then restart the terminal - To restore from environment.yml:
conda env create -f environment.yml - If PATH conflicts occur, use full path:
~/anaconda3/envs/myproject/bin/python script.py
Limitations and Considerations
Large environments with many packages can consume several gigabytes of disk space. Mixing pip and conda in the same environment may cause dependency resolution issues—prefer conda packages when available. Environment names are case-sensitive and cannot contain special characters like @ or #.
Verification Example
# Create test environment conda create -n test_env python=3.9 # Activate and verify conda activate test_env python --version # Should show Python 3.9.x # Check environment is listed conda env list # Should show test_env with asterisk # Clean up conda deactivate conda env remove -n test_env
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.