Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use *some other vispy backend* instead of pyqt5 #86

Closed
wants to merge 5 commits into from
Closed

Conversation

clbarnes
Copy link
Collaborator

PyQt5 causes installation issues on M1 macs (see issue #83).
PyQt is not used explicitly; only as a backend for vispy.

PyQt6 does not seem to have such issues on M1, and selecting it
as a vispy extra rather than a direct dependency should be more robust.

Would appreciate someone with an M1 mac testing out installation and running some 3D plotting.

PyQt5 causes installation issues on M1 macs (see issue #83).
PyQt is not used explicitly; only as a backend for vispy.

PyQt6 does not seem to have such issues on M1, and selecting it
as a vispy extra rather than a direct dependency should be more robust.
@schlegelp
Copy link
Collaborator

schlegelp commented Apr 1, 2022

Perhaps @dokato could take this PR for a spin?

A minimal test would be to run this in a terminal:

>>> import navis
>>> nl = navis.example_neurons()
>>> navis.plot3d(nl)
>>> # Check if 3d viewer pops up. If so, see if we can close it properly:
>>> navis.close3()

@dokato
Copy link
Contributor

dokato commented Apr 1, 2022

Sure.

On arm64, in a fresh environment.

  1. I had to install manually Cython.
  2. Installation was successful
  3. It crashed on:
>>> navis.plot3d(nl)
[...]
File ~/anaconda3/envs/testnavis/lib/python3.9/site-packages/vispy-0.9.6-py3.9-macosx-11.0-arm64.egg/vispy/app/canvas.py:173, in Canvas.__init__(self, title, size, position, show, autoswap, app, create_native, vsync, resizable, decorate, fullscreen, config, shared, keys, parent, dpi, always_on_top, px_scale, backend_kwargs)
    171 # Get app instance
    172 if app is None:
--> 173     self._app = use_app(call_reuse=False)
    174 elif isinstance(app, Application):
    175     self._app = app

File ~/anaconda3/envs/testnavis/lib/python3.9/site-packages/vispy-0.9.6-py3.9-macosx-11.0-arm64.egg/vispy/app/_default_app.py:47, in use_app(backend_name, call_reuse)
     44         return default_app  # Current backend matches backend_name
     46 # Create default app
---> 47 default_app = Application(backend_name)
     48 return default_app

File ~/anaconda3/envs/testnavis/lib/python3.9/site-packages/vispy-0.9.6-py3.9-macosx-11.0-arm64.egg/vispy/app/application.py:47, in Application.__init__(self, backend_name)
     45 self._backend_module = None
     46 self._backend = None
---> 47 self._use(backend_name)

File ~/anaconda3/envs/testnavis/lib/python3.9/site-packages/vispy-0.9.6-py3.9-macosx-11.0-arm64.egg/vispy/app/application.py:258, in Application._use(self, backend_name)
    256         break
    257 else:
--> 258     raise RuntimeError('Could not import any of the backends. '
    259                        'You need to install any of %s. We recommend '
    260                        'PyQt' % [b[0] for b in CORE_BACKENDS])
    262 # Store classes for app backend and canvas backend
    263 self._backend = self.backend_module.ApplicationBackend()

RuntimeError: Could not import any of the backends. You need to install any of ['PyQt4', 'PyQt5', 'PyQt6', 'PySide', 'PySide2', 'PySide6', 'Pyglet', 'Glfw', 'SDL2', 'wx', 'EGL', 'osmesa', 'tkinter']. We recommend PyQt

@clbarnes
Copy link
Collaborator Author

clbarnes commented Apr 1, 2022

I think this is due to some missing compiled components which pip can't handle either way. Could you try the same code, after uninstalling pyqt6 and installing pyside6, just in case? Then maybe try installing qt6 with brew, and make sure you have xcode.

Thanks for your help! Sorry that I don't have an M1 to test on; there are no CI providers either.

@dokato
Copy link
Contributor

dokato commented Apr 1, 2022

Yup, this worked indeed:

$ pip uninstall pyqt6
$ pip install pyside6 

Screenshot 2022-04-01 at 12 10 00

EDIT:
BTW but it looks like there exist some pyqt6 eggs for arm64, this was uninstalled in step 1 from above:

PyQt6-6.2.3-py3.9-macosx-11.0-arm64.egg

@clbarnes
Copy link
Collaborator Author

clbarnes commented Apr 1, 2022

Yeah, pyqt6 universal2 macos wheels do exist, but may dynamically link against something at the system level.

As I understand it, pyqt gained a lot of popularity because it had qt5 support about 2 years before pyside. However, since then pyside has been blessed as the official qt for python, and has a more permissive license, so if it works I don't see any issue switching.

@clbarnes clbarnes changed the title use pyqt6 instead of pyqt5 use *some other vispy backend* instead of pyqt5 Apr 1, 2022
@schlegelp
Copy link
Collaborator

schlegelp commented Apr 1, 2022

Another data point:

With PyQt5 and PyQt6, navis.plot3d works for me in both ipython and normal python console.

With pyside6, it only works from ipython. With normal python, the window doesn't show up. That might be an issue with vispy though?

@clbarnes
Copy link
Collaborator Author

clbarnes commented Apr 1, 2022

Tricky. I don't think I've ever had a "clean" run of qt-based libs in python, and which backend works in which situation seems to be highly dependent on hardware, OS, extra libs, how you call it... a nightmare. Maybe the best thing to do is for vispy with each of its backends to be included as extras (e.g. vispy-pyqt5, vispy-pyside6) etc., have none included by default (to allow everyone to install navis, given that many people don't need 3D vis anyway), and plaster warnings over the docs and places where vispy is imported saying that some experimentation may be required to find a backend which works for you?

@schlegelp
Copy link
Collaborator

Agreed, it is a nightmare. Not sure if my setup is just funky though: do you see the same behaviour with pyside6 and python?

@schlegelp
Copy link
Collaborator

I'd also be game with using pyside6 by default but put up warnings that if people experience problems they should try out PyQt5/6.

@clbarnes
Copy link
Collaborator Author

clbarnes commented Apr 1, 2022

So long as that wouldn't break at install-time or import-time, just use-time (when we can catch it and recommend using another backend). Batteries included is definitely preferable, but it would be easier to ship something which always installs and has optional extra functionality, than something which sends a solid chunk of users scurrying for documentation because it won't install.

@clbarnes
Copy link
Collaborator Author

clbarnes commented Apr 1, 2022

do you see the same behaviour with pyside6 and python

I do 🤦 PyQt 5 and 6 work in python or ipython; pyside6 only works in ipython. Wonder what's going on there.

On the other hand, using a bare python REPL for interactive research stuff is, arguably, doing it wrong...

@clbarnes clbarnes mentioned this pull request Apr 7, 2022
@clbarnes
Copy link
Collaborator Author

clbarnes commented Apr 7, 2022

Closing in favour of #90

@clbarnes clbarnes closed this Apr 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants