1

I am using JModelica for simulation of Modelica models. The JModelica.org Python interface enables users to use Python scripting to interact with Modelica models; but JModelica.org is not only a Python package/library - Python packages are a part of JModelica and not standalone. If you open IPython.bat with JModelica - it call C:\JModelica.org-2.0\setenv.bat. setenv.batdefines and sets different environmental variables including set PYTHONPATH=%JMODELICA_HOME%\Python;%PYTHONPATH% where all the required site-packages are located.

I like to use Anaconda/Spyder for developments and especially for debugging, so it would be great to use JModelica in Spyder. My naive idea would be to create a new environment in Anaconda and use the Intepreter, IPthon, the PYTHONPATH (which is created when /JModelica.org/IPython.batis called) etc. from JModelica.

I know how to create a new environment in Anaconda and how to start Python within that environment. But it does not work.

I also tried to change the settings within Spyder

enter image description here

Another idea is to use the startup file for IPyhon.

enter image description here

Foad S. Farimani
  • 12,396
  • 15
  • 78
  • 193
Matias
  • 581
  • 1
  • 5
  • 16
  • What is the error that you get when you try the above approaches? – Christian Winther Aug 19 '17 at 07:36
  • @ChristianWinther The error message using the above approach is: 'Your Python environment or installation doesn't have the ipykernel and cloudpickle modules installed on it. Without these modules is not possible for Spyder to create a console for you.' Do you know how to install these packages inside the version of Python bundled with JModelica? – alkey Feb 19 '18 at 10:25

2 Answers2

1

I have followed same steps as @Karel Marik.

To get rid of InvalidAlgorithmOptionException exception -

conda install -c conda-forge assimulo
chink
  • 1,505
  • 3
  • 28
  • 70
0

I was able to setup jupyter notebook but I failed with Spyder as you. I tried to

1) start Spyder from Anaconda enviroment with the latest 2.7 Python

2) change Tools -> Preferences -> Python interpreter -> Use the following Python Interpreter

C:\apps\JModelica.org-2.4\Python27\Python_64\python.exe

3) define batch file "spyder64.bat" to run jmodelica environment setup batch. The content of batch file is:

call C:\apps\JModelica.org-2.4\setenv.bat 64
if %errorlevel% neq 0 pause

4) change Tools -> Preferences -> IPython console -> Startup -> Lines

import os, os.system('C://apps//JModelica.org-2.4//spyder64.bat')

5) run hello world python file with code

from pyfmi.examples import fmi_bouncing_ball
fmi_bouncing_ball.curr_dir
fmi_bouncing_ball.run_demo()

... but no luck. I am getting

  File "pyfmi\fmi_algorithm_drivers.py", line 258, in __init__
    self._set_options()

  File "pyfmi\fmi_algorithm_drivers.py", line 425, in _set_options
    "The solver: "+solver+ " is unknown.")

InvalidAlgorithmOptionException: Invalid algorithm options object: The solver: CVode is unknown.

Apparently, the setting of jModelica environment was not successful.

Karel Marik
  • 811
  • 8
  • 13