Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#2652 closed enhancement (fixed)

OMPython missing on MacPorts installer

Reported by: guitorri@… Owned by: Adeel Asghar
Priority: high Milestone: 1.9.1
Component: Installation program Version: 1.9.0Beta
Keywords: Macports; OMPython Cc: dersh@…

Description

The PythonInterface directory is missing in the:

/opt/openmodelica/share/omc/scripts/

in the Macports installer latest-nightly-19836.mpkg

Change History (13)

comment:1 by Martin Sjölund, 11 years ago

The reason for this is that you need a special variant of omniORB or the Python interface won't work. If you want OMPython, you will need to install it from macports manually:

port install python27
port install omniorb+python27
port install py27-omniORBpy
port install openmodelica-devel +python

On OSX/Linux, PythonInterface is not installed into share/omc. Ubuntu listing:

$ apt-file list ompython
ompython: /usr/lib/python2.7/dist-packages/OMPython-1.0.egg-info
ompython: /usr/lib/python2.7/dist-packages/OMPython/OMConfig.py
ompython: /usr/lib/python2.7/dist-packages/OMPython/OMParser/__init__.py
ompython: /usr/lib/python2.7/dist-packages/OMPython/OMTypedParser.py
ompython: /usr/lib/python2.7/dist-packages/OMPython/__init__.py
ompython: /usr/lib/python2.7/dist-packages/OMPython/omc_session.py
ompython: /usr/lib/python2.7/dist-packages/OMPythonIDL/_OMCIDL/__init__.py
ompython: /usr/lib/python2.7/dist-packages/OMPythonIDL/_OMCIDL__POA/__init__.py
ompython: /usr/lib/python2.7/dist-packages/OMPythonIDL/__init__.py
ompython: /usr/lib/python2.7/dist-packages/OMPythonIDL/omc_communication_idl.py
ompython: /usr/share/doc/ompython/changelog.Debian
ompython: /usr/share/doc/ompython/copyright

An alternative is to simply check out OpenModelica svn https://openmodelica.org/svn/OpenModelica/trunk/PythonInterface/ and ru the setup.py

comment:2 by guitorri@…, 11 years ago

Thanks for the info. I was troubleshooting the installation for my students (some on Mac and some on Windows). We did not want to compile Openmodelica, hence the pkg.
As a matter of fact we got all the python and omniorb dependencies from Homebrew, not MacPorts, the only thing that was missing were the OMPython files.

The second alternative worked fine, I could not find the interface at first then we ended up copying from the Windows distribution.

comment:3 by Martin Sjölund, 11 years ago

Good to know. And yes, mixing the homebrew and macports python versions would be another reason to not just install the objects directly to lib/.

Maybe we should just add OMPython to pip install to make things simpler...

comment:4 by Martin Sjölund, 11 years ago

Resolution: fixed
Status: newclosed

pip install ompython should now work, provided you have a Python version of omniorb installed (omniorb is not part of pypi).

comment:5 by Adam Dershowitz <dersh@…>, 11 years ago

I have had issues with getting OMPython to work, and just saw this, so thought that it would be a good opportunity to try it. But I am still not having any luck.

I have installed, from Macports:
omniORB @4.1.6_2+python27 (active)
py27-omniORBpy @3.6

I then did:
sudo pip install ompython
with no errors. But, if I run python then do:
import OMPython
I get the following:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/OMPython/__init__.py", line 88, in <module>
    from omniORB import CORBA
ImportError: No module named omniORB

I realize that this looks like it might be a macports/omni issue, but since you have it working, I thought that you might have some suggestions.

Thanks,

comment:6 by Adam Dershowitz <dersh@…>, 11 years ago

Cc: dersh@… added

Also, when I then quit python, after the failed import, I get this:

>>> quit()
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/OMPython/__init__.py", line 57, in OMPythonExit
    if omc:
NameError: global name 'omc' is not defined
Error in sys.exitfunc:
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/OMPython/__init__.py", line 57, in OMPythonExit
    if omc:
NameError: global name 'omc' is not defined

but, that might just be due the failed import, not getting things setup properly.

comment:7 by Martin Sjölund, 11 years ago

Yes, OMPython has a stupid design with one global object started when importing the module...

And now from what I can see... The macports package for omniORB installs into /opt/local/lib/python2.7/site-packages/ instead of /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/...

>>> import site
>>> site.PREFIXES
['/opt/openmodelica/Library/Frameworks/Python.framework/Versions/2.7', '/opt/openmodelica/Library/Frameworks/Python.framework/Versions/2.7']

So uhmm... Yeah :)

comment:8 by Adam Dershowitz <dersh@…>, 11 years ago

It looks like omniorb +python27 does install things into the expected path:

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/

but py27-omniORBpy puts stuff into:
/opt/local/lib/python2.7/site-packages/

So this seems to function as a work around:

>>> import site
>>> site.addsitedir('/opt/local/lib/python2.7/site-packages/')
>>> import OMPython
OMC Server is down. Please start it! Exiting...

I guess just running OMEdit doesn't configure an omc server that OMPython can connect to?

I will file a ticket with macports to see about getting py27-omniORBpy fixed.

comment:9 by Adam Dershowitz <dersh@…>, 11 years ago

Looks like this is already a known bug with a ticket:
https://trac.macports.org/ticket/35818

comment:10 by Martin Sjölund, 11 years ago

The pip version of ompython does not know which path you installed omc into, so you need to have omc on the PATH, or OPENMODELICAHOME set. The error-message does seem a bit out of place though; we start it with a random string since recent OMPython versions can at least run in parallel.

comment:11 by anonymous, 11 years ago

I just figured out that this works:
export OPENMODELICAHOME=/opt/local/

omc is in PATH, so I am not sure why this is necessary. But now things are working, and macports tends to be responsive to tickets, so perhaps the workaround won't be necessary for long (although the ticket has been around for a long time)

As always, thanks for the help.

comment:12 by Martin Sjölund, 11 years ago

For OPENMODELICAHOME there seems to be a special case:

  # add OPENMODELICAHOME\lib to PYTHONPATH so python can load omniORB libraries
  sys.path.append(os.path.join(omhome, 'lib','python'))
  # add OPENMODELICAHOME\bin to path so python can find the omniORB binaries
  pathVar = os.getenv('PATH')

There is also a log-file opened that might contain an error when opening omc... omc_log_file = open(os.path.join(temp, "openmodelica.omc.output.OMPython"), 'w')

in reply to:  6 comment:13 by Adeel Asghar, 11 years ago

Replying to Adam Dershowitz <dersh@…>:

Also, when I then quit python, after the failed import, I get this:

>>> quit()
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/OMPython/__init__.py", line 57, in OMPythonExit
    if omc:
NameError: global name 'omc' is not defined
Error in sys.exitfunc:
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/OMPython/__init__.py", line 57, in OMPythonExit
    if omc:
NameError: global name 'omc' is not defined

but, that might just be due the failed import, not getting things setup properly.

r20986 should fix this error.

Note: See TracTickets for help on using tickets.