🐍 DS202 β€” Python Environment Setup

2025/26 Winter Term

Author

In this course, you are all expected to use VS Code for running notebooks and working with Python.

We use Conda environments to ensure everyone runs the same software, regardless of operating system.

You will create two environments during the course:

Environment Python When used
py313-core 3.13 Weeks 01–04 (core ML, pandas, evaluation, pipelines)
py312-full 3.12 Weeks 05+ (tree-based models, NLP, autoencoders)

⚠️ Important
Starting in Week 05, you must switch to the Python 3.12 environment.
Tree-based models such as XGBoost, LightGBM, and CatBoost are not reliably supported on Python 3.13.


πŸ”½ Configuration files (download first)

Before you start, download the configuration files from the course repository.

Save all three files in the same folder on your computer.

⬇️ Python 3.13 β€” core environment
Download py313-core.yml

⬇️ Python 3.12 β€” full environment
Download py312-base.yml

⬇️ Extra pip packages (Python 3.12)
Download requirements-py312.txt


1. Install Anaconda

If you haven’t done so already, install Anaconda (latest version) for your operating system:

https://www.anaconda.com/download

During installation:

  • accept the default options (on Windows, try and make sure you install Anaconda for all users and you check the option to add Anaconda to PATH in the installer)
  • do not install another Python distribution separately

2. Open a terminal (inside VS Code)

All commands below should be run inside VS Code.

  1. Open VS Code
  2. Open the course folder
  3. Open a terminal via
    View β†’ Terminal

On different systems, the terminal may be:

  • Windows: Command Prompt or PowerShell
  • macOS: zsh

πŸ’‘ On Windows, CMD or PowerShell is fine as long as conda and python work when you type them.
If they don’t, open Anaconda Prompt, then start VS Code from there.

Check that Conda and Python are available:

conda --version
python --version

3. One-time Conda configuration

Run the following once:

conda config --set channel_priority strict
conda config --set solver libmamba
conda config --add channels conda-forge
conda config --add channels pytorch

This makes installations faster and avoids conflicts.


4. Create the core environment (Python 3.13 β€” Weeks 01–04)

Navigate to the folder where you saved the downloaded files:

cd path/to/your/folder

(obviously replace path/to/your/folder by the actual path to the folder in your computer where you saved the downloaded files!)

Create the environment:

conda env create -f py313-core.yml

Activate it:

conda activate py313-core

Quick check

python -c "import pandas, sklearn; print('py313-core is working')"

5. Register the Python 3.13 kernel for VS Code

python -m ipykernel install \
  --name py313-core \
  --display-name "Python 3.13 (core)"

It could well be that this command can’t run on your system as is (likely on Windows). If that is the case, simply remove the \ characters in this command and make sure the command is all in one line i.e something like bash python -m ipykernel install --name py313-core --display-name "Python 3.13 (core)"

πŸ’‘ In VS Code: Open a notebook (.ipynb), click the kernel selector (top right), and choose Python 3.13 (core).


6. Create the full environment (Python 3.12 β€” from Week 05)

Starting in Week 05, you will switch to a second environment that supports tree-based models and more advanced libraries.

conda env create -f py312-base.yml
conda activate py312-full

7. Install additional packages (pip step β€” Python 3.12 only)

Some packages are only available via pip.

With py312-full activated:

pip install -r requirements-py312.txt

⚠️ Only run the commands in this section once the py312-full environment is activated!


8. Download NLP resources (important)

These datasets are not installed automatically.

Run once in py312-full:

python -m nltk.downloader punkt stopwords
python -m spacy download en_core_web_sm

⚠️ Only run the commands in this section in the activated py312-full environment!


9. Register the Python 3.12 kernel for VS Code

python -m ipykernel install \
  --name py312-full \
  --display-name "Python 3.12 (full)"

πŸ—’οΈ Same remark as in section 5 regarding multiline commands.

πŸ’‘ In VS Code: Open a notebook and select Python 3.12 (full) as the kernel.


10. Final checks

Activate the environment:

conda activate py312-full

Option A β€” One-line check

python -c "import numpy, spacy; from bertopic import BERTopic; print('py312-full is working')"

Option B β€” Interactive check

python

Then type:

import numpy
import spacy
from bertopic import BERTopic
print("py312-full is working")

Exit Python with:

  • Windows: Ctrl+Z then Enter
  • macOS: Ctrl+D

11. Important rules

  • Use VS Code for all labs and assignments
  • Do not install packages in base
  • Always activate the correct environment
  • Do not mix pip and conda unless instructed. conda handles dependencies much better than pip does, so packages should be installed with conda unless they are only available via pip (installing other packages with pip can break your environment).
  • If something breaks badly: delete and recreate the environment

12. Getting help

If you are stuck:

  • copy the exact error message
  • note which environment you are using
  • ask on Slack or during drop-in sessions

Environment issues are much easier to fix early πŸ™‚