Setting up Jupyter Notebook for JModelica

你。 提交于 2019-12-12 09:43:13

问题


I would like to use Jupyter Notebook for editing JModelica python scripts; however after installing, the Jupyter notebook cannot locate key libraries, such as pymodelica.

Here is the process I followed to install Jupyter Notebook for JModelica Version 2.1:

  1. In the IPython terminal: !pip install jupyter

  2. In windows CMD I navigate using cd C:\JModelica.org-2.1\Python27\Scripts

  3. I then open using jupyter notebook

  4. Within the notebook I create a Python 2 file and attempt to import the pymodelica library, which is followed by:

ImportError Traceback (most recent call last) in () ----> 1 import pymodelica

ImportError: No module named pymodelica

Presumably the Jupyter Notebook is running from the Python Kernal installed with JModelica, in which case why is Jupyter Notebook unable to locate the pymodelica library? Are there any settings that need to be changed in order for Jupyter to load these libraries?


回答1:


You need to instruct Python where to find the JModelica.org specific Python packages. The easiest way to do this is to run C:\JModelica.org-2.1\setenv.bat before starting jupyter




回答2:


I addition to what @Jon S mentioned, I want to add that you need to set the environment to 64bit version if you get the error messages like

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-907558296850> in <module>()
----> 1 import pyfmi

C:\JModelica.org-2.10\install\Python\pyfmi\__init__.py in <module>()
     22 
     23 #Import the model class allowing for users to type: from pyfmi import FMUModel
---> 24 from .fmi import FMUModel, load_fmu, FMUModelME1, FMUModelME2
     25 from .fmi import FMUModelCS1, FMUModelCS2
     26 from .fmi_coupled import CoupledFMUModelME2

ImportError: DLL load failed: %1 is not a valid Win32 application.

upon importing any of the JModelica packages. To do so:

  1. open a Windows terminal (cmd, PowerShell, ConEmu...)
  2. navigate to the JModelica installation folder (e.g., cd C:\JModelica.org-2.10 or C:\Users\<user>\AppData\Roaming\JModelica.org-2.10 if you install with Chocolatey)
  3. run setenv.bat 64

Now you should be able to iport all JModelica packages.



来源:https://stackoverflow.com/questions/49051857/setting-up-jupyter-notebook-for-jmodelica

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!