Jupyter在使用OpenModelica的OMPython运行代码时抛出错误“OMC服务器已关闭…”

2024-09-21 05:28:34 发布

您现在位置:Python中文网/ 问答频道 /正文

错误已附加。 我从Temp文件夹中的给定位置打开了该文件,它只包含文本“C:\Program”未被识别为内部或外部命令、可操作程序或批处理文件 任何帮助都将不胜感激

- OMPython - ERROR - OMC Server is down. Please start it! Log-file says:
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
Exception                                 Traceback (most recent call last)
<ipython-input-3-2758f53a36c2> in <module>
----> 1 tank = ModelicaSystem('WaterTank.mo', 'WaterTank.ModWaterTank')
      2 q = tank.getQuantities()
      3 # print('Type of q: ', type(q))
      4 type(q)

~\Anaconda3\lib\site-packages\OMPython\__init__.py in __init__(self, fileName, modelName, lmodel, useCorba)
    679             self.getconn = OMCSession()
    680         else:
--> 681             self.getconn = OMCSessionZMQ()
    682         self.xmlFile = None
    683         self.lmodel = lmodel  # may be needed if model is derived from other model

~\Anaconda3\lib\site-packages\OMPython\__init__.py in __init__(self, readonly, timeout)
    539         self._start_omc_process()
    540         # connect to the running omc instance using CORBA
--> 541         self._connect_to_omc(timeout)
    542 
    543     def __del__(self):

~\Anaconda3\lib\site-packages\OMPython\__init__.py in _connect_to_omc(self, timeout)
    562                     self._omc_log_file.close()
    563                     logger.error("OMC Server is down. Please start it! Log-file says:\n%s" % open(name).read())
--> 564                     raise Exception("OMC Server is down. Could not open file %s" % self._port_file)
    565                 else:
    566                     continue

Exception: OMC Server is down. Could not open file C:/Users/RADICA~1/AppData/Local/Temp/openmodelica.port.7c438238bc7b4cbc89e2f7d57ab2e010

Tags: inselfserverinitislibexceptionnot
2条回答

可能您使用的是较旧的OMPython,对我来说,它可以工作(即使在程序文件中安装了OpenModelica):

E:\bin\py64>python -m pip install -U https://github.com/OpenModelica/OMPython/archive/master.zip
Collecting https://github.com/OpenModelica/OMPython/archive/master.zip
  Downloading https://github.com/OpenModelica/OMPython/archive/master.zip
     - 34 kB 353 kB/s
Collecting future
  Downloading future-0.18.2.tar.gz (829 kB)
     |████████████████████████████████| 829 kB 1.1 MB/s
Requirement already satisfied, skipping upgrade: pyparsing in e:\bin\py64\lib\site-packages (from OMPython==3.1.2) (2.4.6)
Requirement already satisfied, skipping upgrade: numpy in e:\bin\py64\lib\site-packages (from OMPython==3.1.2) (1.18.1)
Requirement already satisfied, skipping upgrade: pyzmq in e:\bin\py64\lib\site-packages (from OMPython==3.1.2) (18.1.1)
Installing collected packages: future, OMPython
    Running setup.py install for future ... done
    Running setup.py install for OMPython ... done
Successfully installed OMPython-3.1.2 future-0.18.2

然后我用的是OMPython:

E:\bin\py64>python.exe
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import OMPython
>>> from OMPython import OMCSessionZMQ
>>> omc = OMCSessionZMQ()
2020-05-21 21:35:58,502 - OMPython - INFO - OMC Server is up and running at file:///C:/Users/adrpo33/AppData/Local/Temp/openmodelica.port.f995e0c74c4b4a7d900ef7442d798b89 pid=20112
>>> model_path=omc.sendExpression("getInstallationDirectoryPath()") + "/share/doc/omc/testmodels/"
>>> print(model_path)
E:/Program Files/OpenModelica1.14.0-64bit//share/doc/omc/testmodels/
>>> from OMPython import ModelicaSystem
>>> mod=ModelicaSystem(model_path + "BouncingBall.mo","BouncingBall")
2020-05-21 21:39:09,024 - OMPython - INFO - OMC Server is up and running at file:///C:/Users/adrpo33/AppData/Local/Temp/openmodelica.port.b631a8f8a6fe4e238c7dca8398fa429d pid=30128
>>> mod.getParameters()
{'e': '0.7', 'g': '9.810000000000001'}
>>> ^Z

您可以尝试通过上面的第一个命令(使用pip)更新您的OMPython

在Windows上使用OMPython_1.18时也存在同样的问题: “OMPython-错误-OMC服务器已关闭。请启动它!日志文件显示: 在“C:\Program”之前,输入的是falsch geschrieben命令 “我不知道。”

这是因为路径“c:\程序文件”中的空白。

我在Python37\lib\site packages\OMPython\uem>init\uupy.py文件中添加了引号,如下所示: self.omhome=“”+omc\u env\u home+“””

这对我很有用

相关问题 更多 >

    热门问题