已附加错误。我从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发布于 2020-05-22 02:49:02
也许你使用的是一个旧的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。
发布于 2021-09-02 19:55:29
在Windows上使用OMPython_1.18时也遇到了同样的问题:"OMPython - ERROR - OMC服务器已关闭。请启动它!日志文件显示: Der Befehl "C:\Program“ist entweder falsch geschrieben oder konnte nicht gefunden werden”
这是因为路径"C:\Program Files“中存在空白。
我在Python37\lib\site-packages\OMPython_.py文件中添加了引号,如下所示: self.omhome =“”+omc_env_home+“
这对我来说很管用。
https://stackoverflow.com/questions/61940393
复制相似问题