Python Co simulation Workaround in UCEF VM - SCU-Smart-Grid-CPS/smart-grid-energy-simulation-research GitHub Wiki
The optimizer simulation requires Python 3.7 or newer. However, the UCEF Version 1.0.0 BETA VM runs an old version of Ubuntu (16.04) where the newest available is Python 3.5! Lots of trial and error; here are the workarounds to save trouble for the future.
Install newer Python using deadsnakes ppa. Terminal commands (paste one line at a time):
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
Note: can install newer versions of Python as they become available; 3.9 was the newest when I did this. In theory anything 3.7 and newer will work. If you choose a different version, substitute that version number instead wherever you see 3.9
sudo apt install python3.9 python3.9-venv python3.9-dev
Then following instructions from https://pip.pypa.io/en/stable/installing/
Paste the following commands in terminal:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3.9 get-pip.py
Note: in Ubuntu 18 and newer, python3 will activate python 3.7, and python will activate python 2.7. Likewise, must use pip3, not pip. However, in Ubuntu 16 (the UCEF VM), we must instead call python3.9, but because it was installed separately pip is just “pip”
Check that it is correct:
python3.9 --version
>> should be 3.9.#
python3.9 -m pip --version
>> should be pip 21 or newer
Code to install packages, where <pkg_name>
is replaced by the name of the package in lower case:
python3.9 -m pip install <pkg_name>
Note: other pip install commands without the python3.9 part will NOT work! It will try to use the old pip
Install the following packages:
- pandas (includes numpy by default)
- os_sys (may not work - gave lots of errors)
- cvxopt
- openpyxl - I installed this because I got an error when running the simulation with only the four listed above. The error said “
ValueError: Your version of xlrd is 2.0.1. In xlrd >= 2.0, only the xls format is supported. Install openpyxl instead.
” - Note: it is likely that xlrd is not needed; if you’re doing this in the future try skipping xlrd and see what happens and update here with the result.
- Update: xlrd not needed. List updated to reflect this
- ipypublish (Optional, for running epPostProcess and showing graphs in Python)
Now the simulation should work. Go to the folder where the simulation is kept, and run the following line to test that it works:
python3.9 energyOptTset2hr.py <range1> <range2> <initial_temperature_°C>
Misc Notes:
- NOT necessary to install or uninstall existing python, python3, pip, pip3, or other packages. Leave whatever is there
- DO NOT update via update manager! Will break VM.
- When installing, it will give annoying warnings about sudo apt autoremove and say a bunch of packages should be removed. Do NOT do this! It is confused and will remove things that are needed!
Python version 3.7 or newer is installed by default, so skip directly to Package Installation. Substitute every instance of python3.9
above with python3
.
Code to install packages, where <pkg_name>
is replaced by the name of the package in lower case:
python3 -m pip install <pkg_name>
Note: other pip install commands without the python3.9 part will NOT work! It will try to use the old pip
Install the following packages:
- pandas (includes numpy by default)
- os_sys (may not work - gave lots of errors)
- cvxopt
- numpy (may be installed by default)
- openpyxl
-
xlrd == 1.2.0
(newer versions of xlrd don't support xlsx files; the older UCEF had an older version working by default) - ipypublish (Optional, for running epPostProcess and showing graphs in Python)
Now the simulation should work. Go to the folder where the simulation is kept, and run the following line to test that it works:
python3 energyOptTset2hr.py <range1> <range2> <initial_temperature_°C>