0

I'm getting the following error when I try to run my code where I want to use PySide2.

objc[18673]: Class RunLoopModeTracker is implemented in both /opt/anaconda3/lib/python3.8/site-packages/PySide2/Qt/lib/QtCore.framework/Versions/5/QtCore (0x11c3c0288) and /opt/anaconda3/lib/libQt5Core.5.9.7.dylib (0x1207e3a80). One of the two will be used. Which one is undefined.
QObject::moveToThread: Current thread (0x7fe94dc18af0) is not the object's thread (0x7fe94df34560).
Cannot move to target thread (0x7fe94dc18af0)

You might be loading two sets of Qt binaries into the same process. Check that all plugins are compiled against the right Qt binaries. Export DYLD_PRINT_LIBRARIES=1 and check that only one set of binaries are being loaded.
qt.qpa.plugin: Could not load the Qt platform plugin "cocoa" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: cocoa, minimal, offscreen.

Abort trap: 6

Unfortunately I have no clue what this means and what to do about it, I tried googling it already but nothing useful has come up!

I'm using Python 3.8.5, PySide 5.15.2 and I'm on Mac OS 10.15.7. Thanks for any help!

2 Answers2

0

I had the same You might be loading two sets of Qt binaries into the same process error with my Qt app when using PyInstaller for packaging.

Using an isolated venv for development, created from anaconda3, everything worked fine! But when the PyInstaller pulled in PySide2 and whatever else it needed from my various env PATHs, the anaconda3 versions of libQt5* that were brought in now conflicted with PySide2 (from my requirements.txt)

After a lots of debugging which dylibs are actually loaded by whom and reading all the SO articles, it slowly dawned on me that anaconda3 was the culprit!!

  • There is precedent for conda package management conflicting with pip based workflow.
  • Carlos Cordoba, a Spyder IDE maintainer, has helped folks resolve issues with installs, which while adjacent to our problem, gets to the essence of the anaconda3 && Qt conflict. Have a look at his comments in the accepted answer

I solved my problem by:

  1. Removing anaconda3 from my env paths (like $PATH) and .bashrc, essentially making it invisible.
  2. Deleted old anaconda3 venvs used to develop my app
  3. Installed a fresh python3.9 from python.org (much more lightweight than anaconda), added it to my $PATH in .bashrc, to make it my primary python3
  4. Re-building venvs to test, I redid PyInstaller packaging and ran the generated app, now this error is gone!
  5. For debugging I set export DYLD_PRINT_LIBRARIES=1, which no longer shows multiple conflicting QtCore dylibs being loaded.

What DID NOT work for me, but was very commonly seen on SO:

  • pip install opencv-python-headless. Ya nope.
  • unset QT_PLUGIN_PATH. This didn't stop the loading of the conflicting libQt5Core
  • any combination of uninstall & reinstalling anaconda3, or PySide2.

To solve your problem, because /opt/anaconda3/lib/libQt5Core.5.9.7.dylib is the root of the conflict, I recommend that you uninstall (or move anaconda3 out of the way) and use a python.org version of python3.8 OR ... use anaconda3 in venv (which is isolated) and install your dependencies directly with pip

ruoho ruotsi
  • 1,283
  • 14
  • 13
0

After installing PySide2 with pip, I was getting the same error.

I did the following:

pip3 uninstall PySide2 

conda install -c conda-forge pyside2

This fixed it for me, and my qt app loaded up when ran via python.

Matt Ellis
  • 451
  • 3
  • 6