08 Configuring Conda & venv#

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. Conda is an environment manager which you can use to create and organise environments and packages inside them. Whiel venv stands for virtual environment and is created inside a project’s directory and by using Python. It is a more lightweight version of conda environments, but it is distributed instead of centralised.

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#

Issue

Cause

Fix

conda: command not found

Conda not added to PATH

Restart terminal or reinstall Miniconda/Anaconda

Environment not activating

Shell not initialized

conda init bash (or zsh, fish, powershell)

Packages won’t install

Wrong channels

Try conda-forge: conda install -c conda-forge <package>

venv#

Issue

Cause

Fix

Activation script not working

Missing permissions

chmod +x myenv/bin/activate

python still points to system Python

Environment not activated

Re-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.