We're Hiring!

Python error import BlitzGateway

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

Python error import BlitzGateway

Postby alexr » Tue May 21, 2019 2:57 pm

Dear all,
I try to include the omero.gateway module into a python script. When I load the module with

Code: Select all
from omero.gateway import BlitzGateway


I get the error:
Code: Select all
    from omero.gateway import BlitzGateway

  File "omero/gateway/__init__.py", line 37, in <module>
    import omero.scripts as scripts

  File "omero/scripts.py", line 28, in <module>
    import omero.util.temp_files

  File "omero/util/temp_files.py", line 343, in <module>
    manager = TempFileManager()

  File "omero/util/temp_files.py", line 52, in __init__
    self.userdir = self.tmpdir() / ("%s_%s" %

  File "omero/util/temp_files.py", line 153, in tmpdir
    targets.append(path(tempfile.gettempdir()) / "omero" / "tmp")

NameError: global name 'path' is not defined


Any help is appreciated.
Thanks
Alex
alexr
 
Posts: 46
Joined: Tue Jun 12, 2018 12:20 pm

Re: Python error import BlitzGateway

Postby jmoore » Tue May 21, 2019 3:22 pm

Hi Alex,

can you give us details about what version of OMERO this is and how you installed it?

Thanks,
~Josh
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: Python error import BlitzGateway

Postby alexr » Tue May 21, 2019 3:30 pm

Hi Josh
the server is a OMERO 5.4.10 with ice 3.6.4. I am running python 2.7 an a client and want to connect to the server. The error occurs on the client, when I try to load the BlitzGateway from the omero.gateway module.
The local library is from the same version as the server (5.4.10, ice 3.6)
Thanks Alex
alexr
 
Posts: 46
Joined: Tue Jun 12, 2018 12:20 pm

Re: Python error import BlitzGateway

Postby Dominik » Wed May 22, 2019 11:53 am

Hi Alex,

do use the Python libraries from the OMERO.server or from the OMERO.py package? Both should work by the way, I'm just trying to replicate the issue.
Could you try to set the PYTHONPATH to only this directory before running the script, e. g. something like
Code: Select all
export PYTHONPATH=/home/user/libs/OMERO.py-5.4.10-ice36-b105/lib/python


Regards,
Dominik
User avatar
Dominik
Team Member
 
Posts: 149
Joined: Mon Feb 10, 2014 11:26 am

Re: Python error import BlitzGateway

Postby alexr » Thu May 23, 2019 10:37 am

Hi Dominik,
I am using the python libraries from the downloaded server. I have the path to the library added in my pythonpath and to make sure it is working I also tried
Code: Select all
sys.path.append("/Users/alexrapp/Documents/OMERO.server-5.4.10-ice36-b105/lib/python")


Nevertheless this still resulted in the path error.
I then went on and generated a new environment, where I placed again only the libraries for Omero and then it works. I think by having other libraries activated it might choose path from a different library with incompatible versions?
See here: https://github.com/pickleshare/pickleshare/issues/8
How can I check or specify which version of path I am loading?
Best wishes
Alex
alexr
 
Posts: 46
Joined: Tue Jun 12, 2018 12:20 pm

Re: Python error import BlitzGateway

Postby jmoore » Mon May 27, 2019 12:32 pm

Hi Alex,

I think I'm still missing something. Can you run the following code before you call sys.append?

Code: Select all
import sys
for p in sys.path:
    print "-->", p
import os
for x in os.environ.keys():
    if x.startswith("OMERO_"):
        print "env:", x, "=", os.environ.get(x, "Missing?")
import path
print "path.py is: ", path.__file__


I get:

Code: Select all
--> /private/tmp/OMERO.py-5.4.10-ice36-b105/lib/python
...
--> /opt/anaconda/lib/python2.7/site-packages/yaclifw-0.2.0-py2.7.egg
path.py is:  /private/tmp/OMERO.py-5.4.10-ice36-b105/lib/python/path.pyc


~Josh
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: Python error import BlitzGateway

Postby alexr » Mon May 27, 2019 1:58 pm

Dear josh,
thanks for the help.
I tested this in the spyder /anaconda editor:
With this:
Code: Select all
import sys
for p in sys.path:
    print "-->", p


print('OMERO:')   
import os
for x in os.environ.keys():
    if x.startswith("OMERO_"):
        print "env:", x, "=", os.environ.get(x, "Missing?")

print('path:')
import path
print "path.py is: ", path.__file__


I get that:
Code: Select all
--> /Users/alexrapp/Documents/INPLACE/env
--> /Users/alexrapp/anaconda2/lib/python27.zip
--> /Users/alexrapp/anaconda2/lib/python2.7
--> /Users/alexrapp/anaconda2/lib/python2.7/plat-darwin
--> /Users/alexrapp/anaconda2/lib/python2.7/plat-mac
--> /Users/alexrapp/anaconda2/lib/python2.7/plat-mac/lib-scriptpackages
--> /Users/alexrapp/anaconda2/lib/python2.7/lib-tk
--> /Users/alexrapp/anaconda2/lib/python2.7/lib-old
--> /Users/alexrapp/anaconda2/lib/python2.7/lib-dynload
--> /Users/alexrapp/anaconda2/lib/python2.7/site-packages
--> /Users/alexrapp/anaconda2/lib/python2.7/site-packages/aeosa
--> /Users/alexrapp/anaconda2/lib/python2.7/site-packages
--> /Users/alexrapp/anaconda2/lib/python2.7/site-packages/IPython/extensions
--> /Users/alexrapp/.ipython
--> /Users/alexrapp/Documents/OMERO.server-5.4.10-ice36-b105/lib/python
--> /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
OMERO:
path:
path.py is:  /Users/alexrapp/anaconda2/lib/python2.7/site-packages/path.pyc


But when I add:
Code: Select all
from omero.gateway import BlitzGateway


I get:
Code: Select all
File "/Users/alexrapp/Documents/test_modules.py", line 24, in <module>
    from omero.gateway import BlitzGateway

  File "omero/gateway/__init__.py", line 37, in <module>
    import omero.scripts as scripts

  File "omero/scripts.py", line 28, in <module>
    import omero.util.temp_files

  File "omero/util/temp_files.py", line 343, in <module>
    manager = TempFileManager()

  File "omero/util/temp_files.py", line 52, in __init__
    self.userdir = self.tmpdir() / ("%s_%s" %

  File "omero/util/temp_files.py", line 152, in tmpdir
    targets.append(get_omero_userdir() / "tmp")

  File "omero/util/__init__.py", line 834, in get_omero_userdir
    return path.path(get_user_dir()) / "omero"

AttributeError: 'module' object has no attribute 'path'


Thanks for your help.
Alex
alexr
 
Posts: 46
Joined: Tue Jun 12, 2018 12:20 pm

Re: Python error import BlitzGateway

Postby jmoore » Mon May 27, 2019 2:10 pm

Thanks for the output. That explains it. Your anaconda installation includes (I assume) https://pypi.org/project/path.py/. Can you try again and insert OMERO's "lib/python" at the front of your sys.path?

Code: Select all
sys.path.insert(0, ...)


This isn't necessarily a full fix, but it will hopefully let us test if your installation can work without path.py.

~Josh.
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: Python error import BlitzGateway

Postby alexr » Tue May 28, 2019 10:05 am

Hi josh,
thanks, that helped. Now the blitzgateway is working with now error thrown up by the path import.
Alex
alexr
 
Posts: 46
Joined: Tue Jun 12, 2018 12:20 pm

Re: Python error import BlitzGateway

Postby jmoore » Tue May 28, 2019 10:13 am

Glad to hear it! We'll look into putting a permanent fix in place, most likely by removing our copy of `path.py` when we move to Python 3.

Cheers,
~Josh
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany


Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 1 guest