This guide explains how to install the Python environment required to run the optimization examples used in the course.
The installation only needs to be done once on your computer.
You must install Python 3.11.
Check whether Python 3.11 is already installed:
python3.11 --version
If the output is something like
Python 3.11.x
you are ready to continue.
If Python 3.11 is not installed, install it using the instructions below.
Download Python 3.11 from
https://www.python.org/downloads/
Run the installer.
Important: during installation check:
Add Python to PATH
python3.11 --version
If you use Homebrew:
brew install python@3.11
Then verify:
python3.11 --version
Install Python 3.11:
sudo apt update
sudo apt install python3.11 python3.11-venv
Then verify:
python3.11 --version
Create a folder for the course and move into it:
mkdir dmor-course
cd dmor-course
Download the file requirements.txt from eClass and place it inside this folder.
Create a private Python environment for the course:
python3.11 -m venv .venv
source .venv/bin/activate
.venv\Scripts\activate
After activation your terminal prompt should start with:
(.venv)
Before installing the packages, upgrade pip:
python -m pip install --upgrade pip
Install all required packages using:
pip install -r requirements.txt
This will install:
Start Python:
python
Then run:
from dmor.model import ModelIf no error appears, the installation was successful.
Exit Python with:
exit()
Download the example files from eClass.
Run an example with:
python example_file.py
Make sure the virtual environment is activated before running examples.
Open a terminal in the course folder and activate the environment.
source .venv/bin/activate
.venv\Scripts\activate
Then run your Python scripts or notebooks.
Check your Python version:
python --version
It must be Python 3.11.
If not, recreate the environment using:
python3.11 -m venv .venv
Use:
python -m pip install -r requirements.txt
instead of pip.
Make sure pip is updated:
python -m pip install --upgrade pip
Installation consists of four commands:
python3.11 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
pip install -r requirements.txt
After this, the environment is ready for all course examples.