5. Redefining the JModelica.org environment

When importing pyjmi or pymodelica in Python, the script startup.py is run which sets the environment used by JModelica.org for the current Python session. For example, the environment variable JMODELICA_HOME points at the JModelica.org installation directory and IPOPT_HOME points at the Ipopt installation directory. One or more of these environment variables set in startup.py can be overridden by a user defined script: user_startup.py.

The script startup.py looks for user_startup.py in the folder

If the script user_startup.py is not found, the default environment variables will be used.

5.1. Example redefining IPOPT_HOME

The following step-by-step procedure will show how to redefine the JModelica.org environment variable IPOPT_HOME:

  1. Go to the folder $USERPROFILE (Windows) or $HOME (Linux). To find out where $USERPROFILE or $HOME points to, open a Python shell and type:

    import os
    os.environ['USERPROFILE']   // Windows
    os.environ['HOME']          // Linux
  2. Create a folder and name it .jmodelica.org (or open it if it already exists)

  3. In this folder, create a text file and name it user_startup.py.

  4. Open the file and type

    environ['IPOPT_HOME']='<new path to Ipopt home>'
  5. Save and close.

  6. Check your changes by opening a Python shell, import pyjmi and check the IPOPT_HOME environment variable:

    import pyjmi