Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Tutorial - Set up Environments

The following section explains how you get from nothing to launching Jupyter Notebook through Anaconda. The explaination below is supported by two videos showing how to do certain steps in Windows. The following Youtube playlists visualize the key steps of this tutorial:

Windows

OSX

Virtual environments

An environment is a directory that contains a specific collection of packages that you have installed.

The advantages of using virtual environments are:

Poetry

Poetry is a dependency manager that automatically handles virtual environments and packages. The steps to install poetry are outlined in the guide below. For additional information on how to install see the official Poetry installation guide.

Poetry installation guide

Step 1: Install Poetry Installing Poetry via command line:

Windows (PowerShell):

(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -

Linux/Mac:

curl -sSL https://install.python-poetry.org | python3 -
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Verify (Linux/Mac/Windows): poetry --version should show version 2.0.0 or higher.

Poetry (version 2.2.1)

Upgrade poetry itself If it does not show poetry version 2 or higher then update poetry with:

poetry self update

Step 2: Poetry for OpenTNSim

# Clone the repository
git clone https://github.com/TUDelft-CITG/OpenTNSim.git
cd OpenTNSim

Install all dependencies (may take some time)

poetry install 

If you want to use notebooks and run tests, then also install the extras

poetry install --extras testing

Step 3: Verify Installation

# Check packages are installed
poetry show

# Test OpenTNSim works
poetry run python -c "import opentnsim; print('opentnsim.__version__')"

uv

uv is a dependency manager that automatically handles virtual environments and packages. The steps to install uv are outlined in the guide below. For additional information on how to install see the official uv installation guide.

uv installation guide

Step 1: Install uv Installing uv via command line:

Windows (PowerShell):

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

Linux/Mac:

curl -LsSf https://astral.sh/uv/install.sh | sh

Verify (Linux/Mac/Windows): uv --version should show version 0.9.12 or higher.

uv 0.9.12

Upgrade uv itself

uv self update

Step 2: uv for OpenTNSim

# Clone the repository
git clone https://github.com/TUDelft-CITG/OpenTNSim.git
cd OpenTNSim

Install all dependencies (may take some time)

uv sync 

If you want to use notebooks and run tests, then also install the extras

uv sync --extra testing

Step 3: Verify Installation

# Check packages are installed
uv pip list

# Test OpenTNSim works
uv run python -c "import opentnsim; print('opentnsim.__version__')"

Using Poetry or uv Commands

TaskPoetry CommandUV Command
Install dependenciespoetry installuv sync
Add a packagepoetry add package-nameuv add package-name
Remove a packagepoetry remove package-nameuv remove package-name
Update packagespoetry updateuv lock --upgrade
List packagespoetry showuv pip list
Run Python scriptpoetry run script.pyuv run script.py
Run testspoetry run pytestuv run pytest
Activate environmentsource .venv/bin/activate (Linux/Mac) or .venv\Scripts\activate (Windows)source .venv/bin/activate (Linux/Mac) or .venv\Scripts\activate (Windows)

NOTE: When you have activated your virtual environment there is no need to include poetry or uv before running your command. You can run your command as is. e.g: pyest or pytest -k test_graph

Conda

Conda is a package manager and environment manager that you use with command line commands at the Anaconda Prompt for Windows, or in a terminal window for macOS or Linux (which is used in this tutorial). Further, Anaconda Navigator is a graphical interface to use conda (not considered in this tutorial).

You have to install Anaconda via https://docs.anaconda.com/anaconda/install/ Once installed, in Windows, go to the Start menu, search for and open “Anaconda Prompt.” In MacOS or Linux, open a terminal window.

A few basic commands are:

When you begin using conda, you already have a default environment named base. You don’t want to put programs into your base environment, though. Create separate environments to keep your programs isolated from each other.

Creating and checking environments

conda create --name opentnsimenv python=3.5

conda activate opentnsimenv

python --version

conda activate

conda info --envs

Installing packages in environments

conda list

conda install numpy

cd [local directory]\notebooks\

pip install -r requirements.txt

Creating an environment including specific packages

conda env create -f environment.yml

conda create --name copied_env --clone original_env

conda list --explicit > spec-file.txt

conda create --name copied_env --file spec-file.txt

Activating an environment and starting Jupyter Notebook

conda activate opentnsimenv

cd C:/Users/correct/directory/...

jupyter notebook

Mamba (instead of Conda)

In case you notice that your computer is slow when using Anaconda, it could be beneficial to install Mamba. Mamba is package manager which can be used with Conda simultaneously. The link listed below takes you to a page where everything from installation to advanced usage of Mamba is explained.