pauldmccarthy / fsleyes

This is a mirror. Feel free to use the issue tracker. PRs welcome.
https://git.fmrib.ox.ac.uk/fsl/fsleyes/fsleyes/
Other
22 stars 11 forks source link

Unable to initialise OpenGL! #98

Closed soichih closed 2 years ago

soichih commented 2 years ago

Hello. I am not sure what I did but fsleyes stopped working on my Ubuntu 21.10 desktop PC (Using X - not wayland).

$fsleyes --version
fsleyes/FSLeyes version 1.3.3

$ fsleyes
   ERROR              main.py  590: initialise      - Unable to initialise OpenGL!
NotImplementedError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/fsleyes/main.py", line 587, in initialise
    fslgl.getGLContext(ready=realCallback)
  File "/usr/local/lib/python3.9/dist-packages/fsleyes/gl/__init__.py", line 490, in getGLContext
    thismod._glContext = GLContext(**kwargs)
  File "/usr/local/lib/python3.9/dist-packages/fsleyes/gl/__init__.py", line 658, in __init__
    self.__createWXGLCanvas()
  File "/usr/local/lib/python3.9/dist-packages/fsleyes/gl/__init__.py", line 804, in __createWXGLCanvas
    attrs = WXGLCanvasTarget.displayAttributes()
  File "/usr/local/lib/python3.9/dist-packages/fsleyes/gl/__init__.py", line 1097, in displayAttributes
    attrs = wxgl.GLAttributes()
SystemError: <class 'wx._glcanvas.GLAttributes'> returned a result with an error set

glxinfo shows that it's working fine

$ glxinfo
name of display: :1
display: :1  screen: 0
direct rendering: Yes
server glx vendor string: NVIDIA Corporation
server glx version string: 1.4
server glx extensions:

Could someone help me troubleshoot this problem?

pauldmccarthy commented 2 years ago

Hi @soichih, what version of wxPython do you have installed, and did you install it from https://extras.wxpython.org/ ?

If you are using a newer version of wxPython, it may have been compiled to use EGL rather than GLX for GL initialisation, which (afaik) is not possible when using X11. You may need to downgrade your wxPython version to 4.0.7 if you want to continue using X11. In the future this may become a run-time, rather than compile-time choice - you can read more about it here.

pauldmccarthy commented 2 years ago

Oh, you may also need to set a PYOPENGL_PLATFORM=x11 environment variable as well, depending on which version of PyOpenGL you have installed.

soichih commented 2 years ago

I had wxPython 4.1.1 installed, and tried to downgrade it to 4.0.7 but I can't get it compiled (with pip3 install wxPython==4.0.7) on my machine (Ubuntu 21.10)

(looong output)

ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-tze2arv_/wxpython_01d01d506a7f428984e64a1ce15c2f94/setup.py'"'"'; __file__='"'"'/tmp/pip-install-tze2arv_/wxpython_01d01d506a7f428984e64a1ce15c2f94/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-ks2wgpgq/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.9/wxPython Check the logs for full command output.
pauldmccarthy commented 2 years ago

Hi @soichih, binary wheels for wxPython are not available on pypi - they are provided for certain versions and Linux distributions at https://extras.wxpython.org/, e.g.:

pip install -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-18.04/ wxpython

However, wheels are only available for LTS Ubuntu releases. How did you install wxPython in the first place?

You could always install FSLeyes using [mini]conda, which is often a much easier process.

soichih commented 2 years ago

I just did pip3 install wxPython which installed wxPython-4.1.1 fine, I think.

I've uninstalled it anyway.

→ sudo pip3 uninstall wxPython 
[sudo] password for hayashis: 
Found existing installation: wxPython 4.1.1
Uninstalling wxPython-4.1.1:
  Would remove:
    /usr/local/bin/helpviewer
    /usr/local/bin/img2png
    /usr/local/bin/img2py
    /usr/local/bin/img2xpm
    /usr/local/bin/pycrust
    /usr/local/bin/pyshell
    /usr/local/bin/pyslices
    /usr/local/bin/pyslicesshell
    /usr/local/bin/pywxrc
    /usr/local/bin/wxdemo
    /usr/local/bin/wxdocs
    /usr/local/bin/wxget
    /usr/local/lib/python3.9/dist-packages/wx/*
    /usr/local/lib/python3.9/dist-packages/wxPython-4.1.1.dist-info/*

I then ran the command you shown there.

sudo pip3 install -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-21.10/ wxpython
Looking in links: https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-21.10/
Collecting wxpython
  Using cached wxPython-4.1.1-cp39-cp39-linux_x86_64.whl
Requirement already satisfied: six in /usr/lib/python3/dist-packages (from wxpython) (1.16.0)
Requirement already satisfied: pillow in /usr/lib/python3/dist-packages (from wxpython) (8.1.2)
Requirement already satisfied: numpy in /usr/lib/python3/dist-packages (from wxpython) (1.19.5)
Installing collected packages: wxpython
Successfully installed wxpython-4.1.1

It looks like it just put the 4.1.1 right back in?

I also downloaded https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-18.04/wxPython-4.0.7.post2-cp37-cp37m-linux_x86_64.whl and installed it via pip3 but it didn't work

sudo pip3 install wxPython-4.0.7.post2-cp37-cp37m-linux_x86_64.whl 
ERROR: wxPython-4.0.7.post2-cp37-cp37m-linux_x86_64.whl is not a supported wheel on this platform.

I'd like to avoid using conda because I easily forget which env that I installed things in.

raamana commented 2 years ago

just wanted to say I also have the same issue on macOS 12.3.1, and would appreciate any fixes.

pauldmccarthy commented 2 years ago

@raamana would you be able to open a new issue?

@soichih - https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-21.10/ is not a valid URL - binary wheels are only available for LTS releases. You can see what's available simply by browsing the https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ site.

Your first pip install command just ended up installing 4.1.1 from your local cache. Do you remember how you installed wxpython in the first place?

In your second pip install command, you tried to install a python 3.7 wheel into a python 3.9 environment. Unfortunately there don't seem to be 3.9 wheels available for 4.0.7.

I'm afraid I can only recommend using [mini]conda - it makes installation much more straightforward. You will continue to run in to problems like this when using pip, unless you are willing to change your OS, or set up your system so that it is able to compile wxpython from source.

pauldmccarthy commented 2 years ago

Or you could switch over to Wayland ...

soichih commented 2 years ago

I've installed it via conda and I was able to get it to work. It took about 12 hours to install fsleyes on conda. I don't like using conda as it's super slow.. but in this case it seems like I don't have an option.

Most of the screen capturing software OBS Studio / Zoom / Fireshot etc.. don't support Wayland so that's not an option for me either.

pauldmccarthy commented 2 years ago

That sounds excessive - it shouldn't take more than a couple of minutes (assuming you have a good internet connection). There might be something up with your conda configuration, which is causing it to struggle to resolve the environment (e.g. you will have problems if you have defaults at a higher priority than conda-forge)

raamana commented 1 year ago

Hi @soichih, did you figure out a workaround?

Hi Paul, I am happy to open another issue if its warranted, but what I encounter is the the same error discussed here, even on the latest fsleyes 1.7.3 on macOS 13:

(base) $ 09:34:39 Quark-2 visualqc >>  fsleyes
Traceback (most recent call last):
  File "/Users/Reddy/anaconda3/envs/py36/lib/python3.7/site-packages/OpenGL/platform/darwin.py", line 38, in GL
    mode=ctypes.RTLD_GLOBAL
  File "/Users/Reddy/anaconda3/envs/py36/lib/python3.7/site-packages/OpenGL/platform/ctypesloader.py", line 36, in loadLibrary
    return _loadLibraryWindows(dllType, name, mode)
  File "/Users/Reddy/anaconda3/envs/py36/lib/python3.7/site-packages/OpenGL/platform/ctypesloader.py", line 89, in _loadLibraryWindows
    return dllType( name, mode )
  File "/Users/Reddy/anaconda3/envs/py36/lib/python3.7/ctypes/__init__.py", line 356, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: ("dlopen(OpenGL, 0x000A): tried: '/Applications/freesurfer/7.2.0/lib/gcc/lib/OpenGL' (no such file), 'OpenGL' (no such file), '/System/Volumes/Preboot/Cryptexes/OSOpenGL' (no such file), '/Users/Reddy/anaconda3/envs/py36/lib/OpenGL' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/Reddy/anaconda3/envs/py36/lib/OpenGL' (no such file), '/Users/Reddy/anaconda3/envs/py36/lib/OpenGL' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/Reddy/anaconda3/envs/py36/lib/OpenGL' (no such file), '/Users/Reddy/anaconda3/envs/py36/lib/OpenGL' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/Reddy/anaconda3/envs/py36/lib/OpenGL' (no such file), '/Users/Reddy/anaconda3/envs/py36/lib/python3.7/lib-dynload/../../OpenGL' (no such file), '/Users/Reddy/anaconda3/envs/py36/lib/OpenGL' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/Reddy/anaconda3/envs/py36/lib/OpenGL' (no such file), '/Users/Reddy/anaconda3/envs/py36/lib/OpenGL' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/Reddy/anaconda3/envs/py36/lib/OpenGL' (no such file), '/Users/Reddy/anaconda3/envs/py36/bin/../lib/OpenGL' (no such file), '/usr/lib/OpenGL' (no such file, not in dyld cache), 'OpenGL' (no such file), '/usr/local/lib/OpenGL' (no such file), '/usr/lib/OpenGL' (no such file, not in dyld cache)", 'OpenGL', None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/Reddy/anaconda3/envs/py36/bin/fsleyes", line 8, in <module>
    sys.exit(main())
  File "/Users/Reddy/anaconda3/envs/py36/lib/python3.7/site-packages/fsleyes/filtermain.py", line 212, in main
    result = fm.main(args)
  File "/Users/Reddy/anaconda3/envs/py36/lib/python3.7/site-packages/fsleyes/main.py", line 238, in main
    fsleyes.initialise()
  File "/Users/Reddy/anaconda3/envs/py36/lib/python3.7/site-packages/fsleyes/__init__.py", line 243, in initialise
    import fsleyes.plugins as plugins
  File "/Users/Reddy/anaconda3/envs/py36/lib/python3.7/site-packages/fsleyes/plugins/__init__.py", line 196, in <module>
    import fsleyes.views.canvaspanel     as canvaspanel
  File "/Users/Reddy/anaconda3/envs/py36/lib/python3.7/site-packages/fsleyes/views/canvaspanel.py", line 20, in <module>
    from . import                    colourbarpanel
  File "/Users/Reddy/anaconda3/envs/py36/lib/python3.7/site-packages/fsleyes/views/colourbarpanel.py", line 15, in <module>
    import fsleyes.gl.wxglcolourbarcanvas as cbarcanvas
  File "/Users/Reddy/anaconda3/envs/py36/lib/python3.7/site-packages/fsleyes/gl/wxglcolourbarcanvas.py", line 17, in <module>
    import fsleyes.gl.colourbarcanvas as cbarcanvas
  File "/Users/Reddy/anaconda3/envs/py36/lib/python3.7/site-packages/fsleyes/gl/colourbarcanvas.py", line 21, in <module>
    import OpenGL.GL as gl
  File "/Users/Reddy/anaconda3/envs/py36/lib/python3.7/site-packages/OpenGL/GL/__init__.py", line 3, in <module>
    from OpenGL import error as _error
  File "/Users/Reddy/anaconda3/envs/py36/lib/python3.7/site-packages/OpenGL/error.py", line 12, in <module>
    from OpenGL import platform, _configflags
  File "/Users/Reddy/anaconda3/envs/py36/lib/python3.7/site-packages/OpenGL/platform/__init__.py", line 36, in <module>
    _load()
  File "/Users/Reddy/anaconda3/envs/py36/lib/python3.7/site-packages/OpenGL/platform/__init__.py", line 33, in _load
    plugin.install(globals())
  File "/Users/Reddy/anaconda3/envs/py36/lib/python3.7/site-packages/OpenGL/platform/baseplatform.py", line 97, in install
    namespace[ name ] = getattr(self,name,None)
  File "/Users/Reddy/anaconda3/envs/py36/lib/python3.7/site-packages/OpenGL/platform/baseplatform.py", line 15, in __get__
    value = self.fget( obj )
  File "/Users/Reddy/anaconda3/envs/py36/lib/python3.7/site-packages/OpenGL/platform/darwin.py", line 62, in GetCurrentContext
    return self.CGL.CGLGetCurrentContext
  File "/Users/Reddy/anaconda3/envs/py36/lib/python3.7/site-packages/OpenGL/platform/baseplatform.py", line 15, in __get__
    value = self.fget( obj )
  File "/Users/Reddy/anaconda3/envs/py36/lib/python3.7/site-packages/OpenGL/platform/darwin.py", line 45, in CGL
    def CGL(self): return self.GL
  File "/Users/Reddy/anaconda3/envs/py36/lib/python3.7/site-packages/OpenGL/platform/baseplatform.py", line 15, in __get__
    value = self.fget( obj )
  File "/Users/Reddy/anaconda3/envs/py36/lib/python3.7/site-packages/OpenGL/platform/darwin.py", line 41, in GL
    raise ImportError("Unable to load OpenGL library", *err.args)
ImportError: ('Unable to load OpenGL library', "dlopen(OpenGL, 0x000A): tried: '/Applications/freesurfer/7.2.0/lib/gcc/lib/OpenGL' (no such file), 'OpenGL' (no such file), '/System/Volumes/Preboot/Cryptexes/OSOpenGL' (no such file), '/Users/Reddy/anaconda3/envs/py36/lib/OpenGL' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/Reddy/anaconda3/envs/py36/lib/OpenGL' (no such file), '/Users/Reddy/anaconda3/envs/py36/lib/OpenGL' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/Reddy/anaconda3/envs/py36/lib/OpenGL' (no such file), '/Users/Reddy/anaconda3/envs/py36/lib/OpenGL' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/Reddy/anaconda3/envs/py36/lib/OpenGL' (no such file), '/Users/Reddy/anaconda3/envs/py36/lib/python3.7/lib-dynload/../../OpenGL' (no such file), '/Users/Reddy/anaconda3/envs/py36/lib/OpenGL' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/Reddy/anaconda3/envs/py36/lib/OpenGL' (no such file), '/Users/Reddy/anaconda3/envs/py36/lib/OpenGL' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/Reddy/anaconda3/envs/py36/lib/OpenGL' (no such file), '/Users/Reddy/anaconda3/envs/py36/bin/../lib/OpenGL' (no such file), '/usr/lib/OpenGL' (no such file, not in dyld cache), 'OpenGL' (no such file), '/usr/local/lib/OpenGL' (no such file), '/usr/lib/OpenGL' (no such file, not in dyld cache)", 'OpenGL', None)
pauldmccarthy commented 1 year ago

Hi @raamana can you double check the version of FSLeyes that you are using? The latest FSLeyes version is 1.5.0.

Your issue is completely unrelated to the original issue here - your issue is due to the fact that macOS versions Big Sur and newer now remove certain shared .dylib files from the file system, and instead place them into an in-memory cache. macOS then intercepts dlopen calls which refer to the full file path, and loads the files from the cache. This is incompatible with the method that Python 3.7 and older use to load shared libraries on macOS, which requires the files to be present in the file system.

The Python folk implemented a solution, but (afaik) this has only been implemented in Python 3.8.10 and newer. I added a hack to the conda-forge FSLeyes package which should have resolved it for older versions of Python.

So in principle all you should have to do is install a newer version of FSLeyes from conda-forge, or to create an environment with a newer Python (3.8.10 or newer).

raamana commented 1 year ago

Thanks for taking a look Paul - I am using the latest fsleyes 1.5.0 with python 3.7.2. Let me try conda forge version and newer 3.8.10 python. I will open a new issue if that doesn't work.

pauldmccarthy commented 1 year ago

In that case it seems that the hack I mentioned is not working for you (I only have limited access to macOS hardware to test these sorts of things). It does also appear that you may have some relevant environment variables set, e.g. DYLD_LIBRARY_PATH. Can you paste the output of env|sort?

pauldmccarthy commented 1 year ago

(note that the hack is only implemented for the conda-forge FSLeyes package - if you have installed FSLeyes via pip, then you will still be affected by the underlying dylib issue)