4

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?

4

2 回答 2

5

您需要指示 Python 在哪里可以找到 JModelica.org 特定的 Python 包。最简单的方法是C:\JModelica.org-2.1\setenv.bat在启动 jupyter 之前运行

于 2018-03-01T16:04:01.777 回答
1

除了@Jon S 提到的内容之外,我想补充一点,如果您收到以下错误消息,您需要将环境设置为 64 位版本

---------------------------------------------------------------------------
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.

在导入任何 JModelica 包时。为此:

  1. 打开一个 Windows 终端(cmd、PowerShell、ConEmu...)
  2. 导航到 JModelica 安装文件夹(例如,cd C:\JModelica.org-2.10或者C:\Users\<user>\AppData\Roaming\JModelica.org-2.10如果您使用Chocolatey安装)
  3. setenv.bat 64

现在您应该可以导入所有 JModelica 包了。

PS对于有兴趣在这里学习和了解更多关于 JModelica 的其他人,我写了一个小教程并收集了许多有用的参考。

于 2019-10-02T23:02:51.320 回答