Goal

Learn how to create, activate, manage, and remove isolated Python environments using Conda and Python’s built-in venv. This ensures clean, reproducible setups for different projects without dependency conflicts.

Prerequisites

Steps

1. Introduction

When working on multiple Python projects, you often need different versions of specific packages or Python itself. Environments are ways to separate versions of packages for different projects and keep different versions isolated.

Why do you need this? Imagine you’re working on two projects: one uses NumPy 1.20 and the other uses NumPy 1.24. If you install both globally on your computer, they’ll conflict. Virtual environments let you have separate, isolated Python installations for each project. Conda is a comprehensive environment manager that can manage both Python versions and packages. Meanwhile, venv is Python’s built-in, lightweight virtual environment tool that works within a single project directory.

2. Setup

2.1 Install Conda

Option 1 — Miniconda (recommended) A minimal, lightweight installer for Conda.

Option 2 — Anaconda Includes Conda + many preinstalled data science packages.

2.2 Ensure Python is Installed (for venv)

Check Python version:

python3 --version

venv comes bundled with Python 3.3+.

3. Execution

3.1 Using Conda

Create a new Conda environment

conda create --name myenv

Create a Conda environment with a specific Python version

conda create --name myenv python=3.10

Activate

conda activate myenv

Deactivate

conda deactivate

List all environments

conda info --envs

Remove an environment

conda env remove --name myenv

3.2 Using Python venv

Create a new environment

python3 -m venv myenv

Activate environment

source myenv/bin/activate

Deactivate

deactivate

Remove a venv environment

Just delete the folder:

rm -rf myenv

4. Verification

Check active environment

Conda:

conda env list

Active environment will be marked with *.

venv:

which python

It should point to the environment folder.

Check installed packages

pip list

Troubleshooting

Conda

IssueCauseFix
conda: command not foundConda not added to PATHRestart terminal or reinstall Miniconda/Anaconda
Environment not activatingShell not initializedconda init bash (or zsh, fish, powershell)
Packages won’t installWrong channelsTry conda-forge: conda install -c conda-forge <package>

venv

IssueCauseFix
Activation script not workingMissing permissionschmod +x myenv/bin/activate
python still points to system PythonEnvironment not activatedRe-run source myenv/bin/activate

Next Steps

You are ready to start working with environemnts, that’s great! However, many times we want to share code among the collaboration and avoid the ‘it-works-on-my-computer’ problem. Environments are a tool to isolate package versions, but they are also heavy. That’s why most of the repositories should have a requirements.txt file, specifing which package you need to install in a conda environment or venv. Anyways, there even is a more straightforward solution 16_docker.