OpenModelica


Forgot password? | Forgot username? | Register

Trouble Installing OMPython

Trouble Installing OMPython

I am following the instructions in the OMPython users manual (Version 2013-01-28 for OpenModelica 1.9.0 Beta3).  I have successfully installed OMPython as outlined in Section 13.3, however, I am unable to successfully test the commands as outlined in Section 13.3.1. 

When I run OMPython.run, I get the following error:

         AttributeError:  'module' object has not attribute 'run'

Administrator has disabled public posting. Please login or register in order to proceed.

Re: Trouble Installing OMPython

Which version of OpenModelica are you using? The same as of the user manual? I your OpenModelica is 1.9.0 Beta3 then it should work.

Adeel.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: Trouble Installing OMPython

I tried using OpenModelica 1.8.1, 1.9.0 Beta3, and 1.9.1 Beta2.  None of them work.  Also, I am using Python 2.7.6 on a Windows 7, 64 bit machine.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: Trouble Installing OMPython

I suggest you should install the latest nightly build https://build.openmodelica.org/omc/buil … y-builds/.
Then try to run this on your python console,

Code:

from OMPython import OMCSession

omc = OMCSession()
omc.execute('getVersion()')

Note that OMPython.run() is removed from the new version. I will update the users guide soon.

Adeel.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: Trouble Installing OMPython

I reinstalled Python and was able to run the test commands in section 13.3.1 (page 138) of the manual.  I am, however, unable to run the commands in section 13.3.2 of the manual. 

When I run the "test.py" Python code I get the following error:
cmds =
         ^
SyntaxError: invalid syntax

Administrator has disabled public posting. Please login or register in order to proceed.

Re: Trouble Installing OMPython

Also, when I type "import OMPython" at my Python command prompt, I get a message stating that the OMC server is up and running, but I also get an error stating the following:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\OMPython\__init__.py", line 115, in <module>
    orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
  File "C:\OpenModelica1.9.0\lib\python\omniORB\CORBA.py", line 541, in ORB_init
    omniORB.orb = ORB(argv, orb_identifier)
  File "C:\OpenModelica1.9.0\lib\python\omniORB\CORBA.py", line 552, in __init__
    _omnipy.ORB_init(self, argv, orb_identifier)
TypeError: argument 2: parameter must be a list of strings.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: Trouble Installing OMPython

Hello everybody..

I am using Python trying to get connected to OpenModelica
I have the exact same error: "OMPython.run()  AttributeError: 'module' object has no attribute 'run"

My 'program':

import OMPython
OMPython.run()

installed OMPython using:
1- setup.py from the Open Modelica 1.9.1 dir
2- pip install OMPython
same results

Help is very welcome !

Administrator has disabled public posting. Please login or register in order to proceed.

Re: Trouble Installing OMPython

help(OMPython) says:

Code:

    Note: Conversion from OMPython 1.0 to OMPython 2.0 is very simple

    1.0:
    import OMPython
    OMPython.execute(command)
    2.0:
    from OMPython import OMCSession
    OMPython = OMCSession()
    OMPython.execute(command)

Administrator has disabled public posting. Please login or register in order to proceed.

Re: Trouble Installing OMPython

Hi sjoelund.se,

That is good to know...

I googled on this error but could not find this info..
(Maybe something to be updated in manuals etc. - for now from now on your answer post will pop up if people google this)

Thanks !,
Leo

Edited by: leo7 - Dec-22-14 07:57:29
Administrator has disabled public posting. Please login or register in order to proceed.

Re: Trouble Installing OMPython

Hmmm there are more things changed as for instance the get


from OMPython import OMCSession
OMPython = OMCSession()
OMPython.execute('getVersion()')

OMPython.execute("loadModel(Modelica)")
OMPython.execute("loadFile(\"C:/OpenModelica1.9.1/testmodels/BouncingBall.mo\")")
result = OMPython.execute("simulate(BouncingBall)")
OMPython.execute("plot(h)")

print '\n' ,'result = ', '\n', result,'\n' ,'\n'

print  OMPython.get(result, 'SET2.Elements.Line3.Properties.Values')

--> Error


Is there any help examples for version 2?

Thanks,
Leo


Administrator has disabled public posting. Please login or register in order to proceed.

Re: Trouble Installing OMPython

# Anyway - the first example working for OMPython  version 2.0
#---------------------
from OMPython import OMCSession
OMPython = OMCSession()
OMPython.execute('getVersion()')

print OMPython.execute("loadModel(Modelica)")
print OMPython.execute  ("loadFile(\"C:/OpenModelica1.9.1/share/doc/omc/testmodels/BouncingBall.mo\")")
result = OMPython.execute("simulate(BouncingBall)")
print OMPython.execute("plot(h)")

print '\n' ,'result = ', '\n', result,'\n' ,'\n'

Administrator has disabled public posting. Please login or register in order to proceed.

Re: Trouble Installing OMPython

I'm having trouble getting OMPython working happily with my Enthought Canopy python installation.   The error message is below.

The python is: Python 2.7.6 --  64-bit

>>> from OMPython import OMCSession
>>> OMPython = OMCSession()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\WRadigan\AppData\Local\Enthought\Canopy\User\lib\site-packages\
ompython-2.0-py2.7.egg\OMPython\__init__.py", line 198, in __init__
    self._connect_to_omc()
  File "C:\Users\WRadigan\AppData\Local\Enthought\Canopy\User\lib\site-packages\
ompython-2.0-py2.7.egg\OMPython\__init__.py", line 119, in _connect_to_omc
    from omniORB import CORBA
  File "C:\OpenModelica1.9.1\lib\python\omniORB\__init__.py", line 254, in <modu
le>
    import _omnipy
ImportError: DLL load failed: %1 is not a valid Win32 application.
>>>



Is a 64bit version of OMPython available?

Administrator has disabled public posting. Please login or register in order to proceed.

Re: Trouble Installing OMPython

No. 64 bit is only available on Linux. Windows versions only support 32 bit.

Adeel.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: Trouble Installing OMPython

I am trying to run OMPython on mac. I installed OMPython through pip and omniORB packages through homebrew. I am able to import OMPython but when I use OMCSession I get an error saying "omniORBpy version 4.2 expects stubs version 4.2. Stubs in /usr/local/lib/python2.7/site-packages/OMPythonIDL/omc_communication_idl.pyc are version 3.0 (rev 0)".

Administrator has disabled public posting. Please login or register in order to proceed.

Re: Trouble Installing OMPython

This is the error message

>>> from OMPython import OMCSession
>>> OMPython = OMCSession()
omniORB: (0) 2016-06-17 18:12:26.970936: ERROR! omniORBpy version 4.2 expects stubs version 4.2. Stubs in /usr/local/lib/python2.7/site-packages/OMPythonIDL/omc_communication_idl.pyc are version 3.0 (rev 0).
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/OMPython/__init__.py", line 192, in __init__
    self._connect_to_omc()
  File "/usr/local/lib/python2.7/site-packages/OMPython/__init__.py", line 125, in _connect_to_omc
    from OMPythonIDL import _OMCIDL
  File "/usr/local/lib/python2.7/site-packages/OMPythonIDL/_OMCIDL/__init__.py", line 9, in <module>
    import OMPythonIDL.omc_communication_idl
  File "/usr/local/lib/python2.7/site-packages/OMPythonIDL/omc_communication_idl.py", line 7, in <module>
    _omnipy.checkVersion(3,0, __file__)
ImportError: Stubs not compatible with omniORBpy version 4.2.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: Trouble Installing OMPython

Did you install onniidl-python before pip install? If it's not available, it uses a pre-generated Python file which might not match your omniorb version.

Administrator has disabled public posting. Please login or register in order to proceed.
There are 0 guests and 0 other users also viewing this topic