FMU Dependencies
Often, Python scripts depends on non-builtin libraries like numpy, scipy, etc.
PythonFMU3 does not package a full environment within the FMU.
However, you can package a requirements.txt or environment.yml file within your FMU following these steps:
- Install pythonfmu3 package:
pip install pythonfmu3 - Create a new class extending the
Fmi3Slaveclass declared in thepythonfmu3.fmi3slavemodule (see below for an example). - Create a
requirements.txtfile (to use pip manager) and/or aenvironment.ymlfile (to use conda manager) that defines your dependencies. - Run
pythonfmu3 build -f myscript.py requirements.txtto create the fmu including the dependencies file.
And using pythonfmu3 deploy, end users will be able to update their local Python environment. The steps to achieve that:
- Install pythonfmu3 package:
pip install pythonfmu3 - Be sure to be in the Python environment to be updated. Then execute
pythonfmu3 deploy -f my.fmu
usage: pythonfmu3 deploy [-h] -f FMU [-e ENVIRONMENT] [{pip,conda}]
Deploy a Python FMU. The command will look in the `resources` folder for one of the following files:
`requirements.txt` or `environment.yml`. If you specify a environment file but no package manager, `conda` will be selected for `.yaml` and `.yml` otherwise `pip` will be used. The tool assume the Python environment in which the FMU should be executed is the current one.
positional arguments:
{pip,conda} Python packages manager
optional arguments:
-h, --help show this help message and exit
-f FMU, --file FMU Path to the Python FMU.
-e ENVIRONMENT, --env ENVIRONMENT
Requirements or environment file.