【问题标题】:QT Binaries Problem : Unable to use PySide2QT 二进制文件问题:无法使用 PySide2
【发布时间】:2022-07-05 12:10:21
【问题描述】:

当我尝试在我想使用 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

不幸的是,我不知道这意味着什么以及如何处理它,我已经尝试在谷歌上搜索它,但没有任何有用的信息出现!

我使用的是 Python 3.8.5、PySide 5.15.2,并且我使用的是 Mac OS 10.15.7。感谢您的帮助!

【问题讨论】:

    标签: python macos qt pyside2


    【解决方案1】:

    在使用 PyInstaller 进行打包时,我的 Qt 应用程序出现了相同的 You might be loading two sets of Qt binaries into the same process 错误。

    使用从anaconda3 创建的独立venv 进行开发,一切正常!但是,当 PyInstaller 从我的各种 env PATH 中提取PySide2 以及它需要的任何其他内容时,引入的libQt5*anaconda3 版本现在与PySide2 冲突(来自我的requirements.txt

    经过大量调试哪些 dylib 实际由谁加载并阅读所有 SO 文章后,我慢慢意识到anaconda3 是罪魁祸首!!

    • precedent 用于 conda 包管理与基于 pip 的工作流冲突。
    • Carlos Cordoba,Spyder IDE 维护者,帮助人们解决了安装问题,虽然与我们的问题相邻,但也触及了anaconda3 && Qt 冲突的本质。看看his comments in the accepted answer

    我通过以下方式解决了我的问题:

    1. 从我的环境路径(如$PATH)和.bashrc 中删除anaconda3,实质上使其不可见。
    2. 删除了用于开发我的应用的旧 anaconda3 venvs
    3. 从 python.org 安装了一个新的python3.9(比 anaconda 更轻量级),将它添加到我的.bashrc 中的$PATH,使其成为我的主要python3
    4. 重新构建 venvs 进行测试,我重新打包 PyInstaller 并运行生成的应用程序,现在这个错误消失了!
    5. 为了调试,我设置了export DYLD_PRINT_LIBRARIES=1,它不再显示正在加载多个冲突的 QtCore dylib。

    什么对我不起作用,但在 SO 上很常见:

    • pip install opencv-python-headless。不。
    • unset QT_PLUGIN_PATH。这并没有停止加载冲突的libQt5Core
    • 卸载和重新安装anaconda3PySide2的任意组合。

    为了解决您的问题,因为/opt/anaconda3/lib/libQt5Core.5.9.7.dylib 是冲突的根源,我建议您卸载(或将anaconda3 移开)并使用python.org 版本的python3.8 或...在 venv(隔离)中使用 anaconda3 并使用 pip 直接安装您的依赖项

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-08
      • 2021-07-29
      相关资源
      最近更新 更多