Python¶
MIKE OPERATIONS is using Python as scripting language.
Python versions¶
The schema below shows what versions of Python are embedded into the MIKE OPERATIONS releases.
Python Enhancement Proposals (PEP) refers to the official Python release schedule for the embedded CPython versions.
Note
The embedded IronPython version is not expected to be upgraded with future versions of MIKE OPERATIONS. This can change if IronPython starts releasing updated (and supported) Python versions.
Release | IronPython | CPython | Python Enhancement Proposals (PEP) | Notes |
---|---|---|---|---|
2025.2 | 2.7.12 | 3.11.9 | Python 3.11 Release Schedule | |
2025 | 2.7.12 | 3.11.9 | Python 3.11 Release Schedule | Supported custom versions of Python are 3.7 - 3.12 Python 3.11 is recommended. Using Python 3.12.* will work, but will not be able to watch values while debugging scripts. |
2024.3 | 2.7.12 | 3.11.9 | Python 3.11 Release Schedule | Supported custom versions of Python are 3.7 - 3.11 |
2024.2 | 2.7.12 | 3.11.9 | Python 3.11 Release Schedule | Supported custom versions of Python are 3.7 - 3.11 |
2024.1 | 2.7.12 | 3.11.7 | Python 3.11 Release Schedule | Supported custom versions of Python are 3.7 - 3.11 |
2024 | 2.7.12 | 3.9.13 | Python 3.9 Release Schedule | |
2023.4 | 2.7.9 | 3.9.13 | Python 3.9 Release Schedule | |
2023.3 (obsolete) | 3.4.1 | 3.9.10 | Python 3.9 Release Schedule | |
2023.2 | 2.7.9 | 3.9.10 | Python 3.9 Release Schedule | |
2023.1 | 2.7.9 | 3.9.10 | Python 3.9 Release Schedule | |
2023 | 2.7.9 | 3.9.10 | Python 3.9 Release Schedule | |
2022.1 | 2.7.7 | 3.9.10 | Python 3.9 Release Schedule | |
2022 | 2.7.7 | 3.7.3 | Python 3.7 Release Schedule | |
2021.1 | 2.7.7 | 3.7.3 | Python 3.7 Release Schedule | |
2021 | 2.7.7 | 3.7.3 | Python 3.7 Release Schedule |
MIKE OPERATIONS will embed the latest bug fix release of the current minor version of Python (Python bugfixe releases are expected every two months).
Minor versions (3.x), released by Python every year, will be updated embedded in MIKE OPERATIONS when the Python minor version has been released for at least a year.
Note
After MIKE OPERATIONS version 2024.1, minor Python versions is expected to be upgraded with every major MIKE OPERATIONS release. See expected Python versions below (subject to change).
Release | IronPython | CPython | Python Enhancement Proposals (PEP) |
---|---|---|---|
2026 (expected Nov 2025) | 2.7.12 | 3.13.6 | Python 3.13 Release Schedule |
For more information about official Python support and the Python release cycle, refer to the Python Developer's Guide.
IronPython¶
A new script storage is by default using a .NET implementation of Python IronPython.
IronPython is an excellentaddition to the .NET ecosystem, providing Python developers with the power of .NET. Existing .NET developers can also use IronPython as a fast and expressive scripting language.
IronPython aims to be a fully compatible implementation of the Python language. At the same time, the value of a separate implementation than CPython is to make available the .NET ecosystem of libraries. IronPython does this byexposing .NET concepts as Python entities. Existing Python syntax and new Python libraries (like clr) are used to make .NET features available to IronPython code.
IronPython does NOT support C-API extensions like signal and numpy. To get a list of available build-in modules, write the following code:
import sys
print(sys.builtin_module_names)
With MIKE OPERATIONS 2023.3 and later versions, the following build-in modules are available.
'_ast', '_bisect', '_bz2', '_codecs', '_collections', '_csv', '_ctypes', '_ctypes_test', '_datetime', '_functools', '_heapq', '_imp', '_io', '_locale',
'_md5', '_multiprocessing', '_opcode', '_operator', '_overlapped', '_random', '_sha1', '_sha256', '_sha512', '_socket', '_sre', '_ssl', '_string', '_struct',
'_thread', '_warnings', '_weakref', '_winapi', 'array', 'atexit', 'audioop', 'binascii', 'builtins', 'clr', 'cmath', 'errno', 'faulthandler', 'gc', 'itertools',
'marshal', 'math', 'mmap', 'msvcrt', 'nt', 'pyexpat', 'pyexpat.errors', 'pyexpat.model', 're', 'select', 'signal', 'sys', 'time', 'unicodedata', 'winreg', 'winsound',
'xxsubtype', 'zipimport', 'zlib'
On top of the build-in modules, a long list of additional modules are installed with MIKE OPERATIONS. A complete list of the modules installed, see the installation folder
in C:\Program Files (x86)\DHI\MIKE OPERATIONS\<version>\bin\python-stdlib\ironpython\
The list includes but not limitted to the following modules.
email, encodings, html, http, json, sqlite3, xml
To execute IronPython scripts, install the NuGet package DHI.MikeOperations.ScriptManager.IronPython
.
Note
Note that the IronPython version upgraded in MIKE OPERATIONS 2023.3 has been reverted back to 2.7.12 with release 2024, because of the many changes that should be made to scripts as well as critical issues with the IronPython 3.4 version. This means that when using IronPython scripts, only Python 2 is supported. There are currently no plans for upgrading IronPython scripts to Python 3. If Python 3 is needed, use the CPython implementation of the script manager, setting the script storage type to CPython.
CPython¶
As an alternative to IronPython, CPython is supported using PythonNet. Note that the PythonNet package does not implement Python as a first-class CLR language - it does not produce managed code(IL) from Python code. Rather, it is an integration of the CPython engine with the .NET or Mono runtime. This approach allows you to use CLR services and continue to use existing Python code and C-API extensions while maintaining native execution speeds for Python code. If you are interested in a pure managed-code implementation of the Python language, you should check out the IronPython project, which is in active development.
The CPython implementation of MIKE OPERATIONS 2023.3 contains the default Python modules of the Python version as well as a number of additional modules (with dependencies).
More modules can be installed using pip
.
The table below, shows what Python libraries/modules are installed with the various MIKE OPERATIONS versions, when the Python Libraries for FEFLOW option is selected when installing MIKE OPERATIONS.
- Installation Method pip means that the module/library is installed as a required library for the FEFLOW and MODFLOW model adapters.
- Installation Method Dependency means that the module/library is installed as a dependency to one of the libraries installed with pip.
Python module | Installation Method | 2024 | 2024.1 | 2024.2 | 2024.3 | 2025 | 2025.2 |
---|---|---|---|---|---|---|---|
attrs | Dependency | 23.1 | 23.1 | 23.1 | 23.1 | 23.1 | 25.3.0 |
certifi | Dependency | 2023.7.22 | 2023.11.17 | 2023.11.17 | 2023.11.17 | 2023.11.17 | 2025.4.26 |
cffi | Dependency | 1.17.1 | |||||
cftime | Dependency | 1.6.4 | |||||
click | Dependency | 8.1.7 | 8.1.7 | 8.1.7 | 8.1.7 | 8.1.7 | 8.2.0 |
click_plugins | Dependency | 1.1.1 | 1.1.1 | 1.1.1 | 1.1.1 | 1.1.1 | 1.1.1 |
cligj | Dependency | 0.7.2 | 0.7.2 | 0.7.2 | 0.7.2 | 0.7.2 | 0.7.2 |
clr_loader | Dependency | 0.2.7 | |||||
colorama | Dependency | 0.4.6 | 0.4.6 | 0.4.6 | 0.4.6 | 0.4.6 | 0.4.6 |
contourpy | Dependency | 1.1.0 | 1.2.0 | 1.2.0 | 1.2.0 | 1.2.0 | 1.3.2 |
cycler | Dependency | 0.11.1 | 0.12.1 | 0.12.1 | 0.12.1 | 0.12.1 | 0.12.1 |
dateutil | Dependency | 2.8.2 | 2.8.2 | 2.8.2 | 2.8.2 | 2.8.2 | 2.9.0 |
fiona | pip | 1.9.4 | 1.9.5 | 1.9.5 | 1.9.5 | 1.9.5 | 1.10.1 |
flopy | pip | N/A | N/A | N/A | 3.6.0 | 3.6.0 | 3.9.2 |
fontTools | Dependency | 4.42.1 | 4.45.1 | 4.45.1 | 4.45.1 | 4.45.1 | 4.58.0 |
geopandas | pip | 0.14.0 | 0.14.1 | 0.14.1 | 0.14.1 | 0.14.1 | 1.0.1 |
importlib_metadata | Dependency | 6.8.0 | N/A | N/A | N/A | N/A | N/A |
importlib_resources | Dependency | 6.1.0 | N/A | N/A | N/A | N/A | N/A |
Jinja2 | Dependency | 3.1.6 | |||||
kiwisolver | Dependency | 1.4.5 | 1.4.5 | 1.4.5 | 1.4.5 | 1.4.5 | 1.4.8 |
MarkupSafe | Dependency | 3.0.2 | |||||
matplotlib | pip | 3.8.0 | 3.8.2 | 3.8.2 | 3.8.2 | 3.8.2 | 3.10.0 |
mikecore | Dependency | 0.2.1 | 0.2.1 | 0.2.1 | 0.2.1 | 0.2.1 | 0.2.2 |
mikeio | pip | 1.6.2 | 1.6.3 | 1.6.3 | 1.6.3 | 1.6.3 | 2.4.0 |
mikeio1d | pip | 1.0.3 | |||||
mikeplus | pip | 2025.0.2 | |||||
modelskill | pip | 1.1.0 | |||||
numpy | pip | 1.26.0 | 1.26.2 | 1.26.2 | 1.26.2 | 1.26.2 | 2.2.5 |
packaging | Dependency | 23.1 | 23.2 | 23.2 | 23.2 | 23.2 | 25.0 |
pandas | pip | 2.1.1 | 2.1.3 | 2.1.3 | 2.1.3 | 2.1.3 | 2.2.3 |
pillow | Dependency | 10.0.1 | 10.1.0 | 10.1.0 | 10.1.0 | 10.1.0 | 11.2.1 |
pyparsing | Dependency | 3.1.1 | 3.1.1 | 3.1.1 | 3.1.1 | 3.1.1 | 3.2.3 |
pycparser | Dependency | 2.22 | |||||
pyogrio | Dependency | 0.11.0 | |||||
typing_extensions | Dependency | 4.13.2 | |||||
pyproj | pip | 3.6.1 | 3.6.1 | 3.6.1 | 3.6.1 | 3.6.1 | 3.7.1 |
pytz | Dependency | 2023.3 | 2023.3 | 2023.3 | 2023.3 | 2023.3 | 2025.2 |
PyYAML | Dependency | 6.0.1 | 6.0.1 | 6.0.1 | 6.0.1 | 6.0.1 | 6.0.2 |
scipy | pip | 1.11.2 | 1.11.4 | 1.11.4 | 1.11.4 | 1.11.4 | 1.15.2 |
setuptools | Dependency | N/A | 69.0.2 | 69.0.2 | 69.0.2 | 69.0.2 | 65.5.0 |
shapely | Dependency | 2.0.1 | 2.0.2 | 2.0.2 | 2.0.2 | 2.0.2 | 2.1.0 |
six | Dependency | 1.16.0 | 1.16.0 | 1.16.0 | 1.16.0 | 1.16.0 | 1.17.0 |
tqdm | Dependency | 4.66.1 | 4.66.1 | 4.66.1 | 4.66.1 | 4.66.1 | 4.67.1 |
tzdata | Dependency | 2023.3 | 2023.3 | 2023.3 | 2023.3 | 2023.3 | 2025.2 |
xarray | Dependency | 2023.8 | 2023.11 | 2023.11 | 2023.11 | 2023.11 | 2025.4.0 |
zipp | Dependency | 2023.8 | N/A | N/A | N/A | N/A | N/A |
The installed modules/libraries can be found in the MIKE OPERATIONS installation folder in C:\Program Files (x86)\DHI\MIKE OPERATIONS\<version>\bin\python-stdlib\python\site-packages\
Note
Note that CPython is type safe. This means that e.g. modules should be casted to the required module types.
The sample below shows an example on casting in CPython.
# Get the module (type IModule) and cast it into the correct type (ITimeSeriesModule).
module = app.Modules.Get('Time series Manager');
tsModule = DHI.Solutions.TimeseriesManager.Interfaces.ITimeSeriesModule(module)
ts = tsModule.TimeSeriesList.Fetch('/Telemetry/Catchment rainfall/3250_SAVA_BOHINJKA_BODESCE_Rainfall.dfs0 [weighted]')
vpList = ts.FetchAll()
castList = System.Collections.Generic.List[DHI.Solutions.Generic.IDataSeriesValuePair]()
# Loop the time steps and add them to a new list.
for vp in vpList:
castList.Add(vp)
# Create a new time step and add it to the list.
vpNew = ts.CreateNew()
vpNew.XValue = System.DateTime.Now
vpNew.YValue = 5
castList.Add(vpNew)
ts.SetData(castList);
tsModule.TimeSeriesList.Update(ts);
Custom Python versions¶
From MIKE OPERATIONS 2024.1, support for using custom Python installations has been added.
Define the Python version in the script explorer (property: CPython DLL Path) by specifying the full path of the Python DLL to use e.g. C:\Users\kth\AppData\Local\Programs\Python\Python311\python311.dll
.
Python installers can be found on python.org/downloads.
Python versions are by default installed into the user local programs folder %LocalAppData%\Programs\Python\<version>
.
Please refer to Using Pip to import Python Modules on how MIKE OPERATIONS identifies the Python installation used.
The following custom versions of Python are supported.
MIKE OPERATIONS Version | Supported Python versions | Notes |
---|---|---|
2025.0 | 3.7 - 3.12 | Python 3.12. will run, but will not allow variable watch during debugging in the MIKE Workbench script editor.* |
2024.3 | 3.7 - 3.11 | |
2024.2 | 3.7 - 3.11 | |
2024.1 | 3.7 - 3.11 |
Python v2 to Python v3¶
Moving from IronPython to CPython requires that scripts follow the syntax of Python 3 instead of Python 2 being used in IronPython.
Moving from Python version 2. to Python 3., requires some changed to the Python code.
Python 3.* improves the Python experience.
- Python 3 provides a simpler syntax compared to Python 3.
- A long list of new and improved Python libraries.
- Open Source with a large community base.
- User friendly data structure.
- Faster engine.
When upgrading from earlier versions of MIKE OPERATIONS, scripts written in Python, could potentially not be able to compile. In most cases, it is very simle to fix these errors.
PRINT
is now a method. Useprint()
.<>
inIF
statments are not allowed. Use!=
.
Also note that integer division now always return a float and not sometimes an int. 6/3 = 2.0
and not 6/3 = 2
.
Check out the automated Python 2 to Python 3 converter.
Importing Python modules¶
The CPython implementation supports importing additional Python modules using pip
.
Note
It is important that modules are installed into the library folder of of the Python installation being used.
By default, the embedded Python installation of MIKE OPERATIONS is used, located in C:\Program Files (x86)\DHI\MIKE OPERATIONS\<version>
.
The following sample shows how to import the numpy module.
- Open a cmd prompt and run
cd /d C:\Users\<user>\AppData\Local\Programs\Python\Python<version>\Scripts
- Run the command
pip install --target="C:\Program Files (x86)\DHI\MIKE OPERATIONS\<version>\bin\python-stdlib\python\site-packages" numpy
.
The folderC:\Program Files (x86)\DHI\MIKE OPERATIONS\<version>
is the installation folder of MIKE OPERATIONS. - Open MIKE Workbench and create a storage. Remember to change the script type in the property grid to CPython.
- The script below will use the imported numpy module
import numpy as np
def PrintArray():
a = np.array([1,2,3,4,5])
np.savetxt(r"c:\Temp\array.txt",a)
Info
Make sure that the library path specified in pip install <module> --target=<library path>
is correct when installing new Python libraries.
Python 3rd party editors¶
The MIKE OPERATIONS .NET API can be used with 3rd party Python editors like Visual Studio Code.
This can be done, either by using an existing MIKE OPERATIONS installation or by building a dedicated application based on NuGet packages needed.
Note
Using 3rd party Python editors is supported with MIKE OPERATIONS 2024 and later versions.
Note
Using a version of MIKE OPERATIONS installed with the MIKE OPERATIONS installer, only support targeting the .NET Framework.
Create a .NET application for Python developmnent¶
Follow the steps in the getting started section of the MIKE OPERATIONS SDK.
- Create a project
- Set target SDK and the runtime
- Build the application
- Run the application to create a runtime.config
Refer to the Getting Started section on how to create a .NET project and application.
Install the pythonnet library¶
Install the PythonNet library using the following command from a Python command prompt.
pip install pythonnet