spyder-ide / qtpy

Provides an uniform layer to support PyQt5, PySide2, PyQt6, PySide6 with a single codebase
MIT License
955 stars 151 forks source link

Getting `RuntimeWarning: Selected binding "pyside6" could not be found, using "pyqt5"` what to do? #395

Open jain-brain opened 1 year ago

jain-brain commented 1 year ago

I am receiving the following error. I have searched the internet everywhere for the solution. Can you please tell me how to resolve this? Is this due to incompatibility of versions of the library?

/lib/python3.9/site-packages/qtpy/__init__.py:267: RuntimeWarning: Selected binding "pyside6" could not be found, using "pyqt5" warnings.warn('Selected binding "{}" could not be found, '

CAM-Gerlach commented 1 year ago

From the minimal information provided above, this itself is just a warning, rather than an error, indicating that QtPy could not find an installed Qt binding (PyQt or PySide) in your current environment. The simple solution is to simply install one (PyQt5 or 6, or PySide2 or 6) using whatever package manager (pip, conda or OS) you are already using for your Python environment (virtualenv, conda env, etc).

Beyond that, we'll need a lot more information to be able to provide more specific advice. In particular:

Also, please paste the full commands and output you are attempting inside a code block, i.e.

```
<Paste full commands and output here>
```

And also paste the full conda list (if using a conda based Python distribution) or pip list (otherwise) output in the same:

```
<Paste full pip/conda list output>
```

Thanks!

dalthviz commented 1 year ago

Could it be worthy to add some descriptions to the README regarding possible warnings that QtPy can show @CAM-Gerlach ?

CAM-Gerlach commented 1 year ago

It would probably be worth fully documenting the error and warning hierarchy defined in __init__, yeah, at least at some point. However, at least in terms of end user interpretation (as appears to be the case here), the messages themselves should be clear and easy enough to understand on their own first and foremost—and right now, there's only one general warning defined, with a rather inaccurate/outdated docstring, and it isn't even used here (instead, a generic RuntimeWarning is used).

To clean up the warning class, message and docstring while remaining fully backwards compatible, I've opened PR #398

dalthviz commented 1 year ago

Checking again the OP I think the warning was triggered due to the @jain-brain setup not having PySide6 installed, setting PySide6 as QT_API and importing PyQt5 before importing QtPy. Basically the way to not see the warning is either installing pyside6 in the environment from where QtPy is running or setting the environment variable QT_API to the name of the binding that actually installed (QT_API=pyqt5)