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:
In the IPython terminal:
!pip install jupyter
In windows CMD I navigate using
cd C:\JModelica.org-2.1\Python27\Scripts
I then open using
jupyter notebook
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?
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
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:
- open a Windows terminal (cmd, PowerShell, ConEmu...)
- navigate to the JModelica installation folder (e.g.,
cd C:\JModelica.org-2.10
orC:\Users\<user>\AppData\Roaming\JModelica.org-2.10
if you install with Chocolatey) - 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