【无法根治但绝对管用】运行rqt报错PyCapsule_GetPointer called with incorrect name解决办法

  最近在做机械臂手眼标定的时候发现ubuntu的rqt命令总是报错:ValueError: PyCapsule_GetPointer called with incorrect name,窗口无法显示,打开rqt_graph之类的也会报错,但是窗口可以打开,折腾好久总算把问题解决了,做个记录。
我的报错如下:

Traceback (most recent call last):
  File "/opt/ros/noetic/bin/rqt", line 13, in 
    sys.exit(main.main())
  File "/opt/ros/noetic/lib/python3/dist-packages/rqt_gui/main.py", line 61, in main
    return super(
  File "/opt/ros/noetic/lib/python3/dist-packages/qt_gui/main.py", line 407, in main
    from python_qt_binding import QT_BINDING
  File "/opt/ros/noetic/lib/python3/dist-packages/python_qt_binding/__init__.py", line 55, in 
    from .binding_helper import loadUi, QT_BINDING, QT_BINDING_MODULES, QT_BINDING_VERSION  # @UnusedImport
  File "/opt/ros/noetic/lib/python3/dist-packages/python_qt_binding/binding_helper.py", line 277, in 
    _select_qt_binding(
  File "/opt/ros/noetic/lib/python3/dist-packages/python_qt_binding/binding_helper.py", line 111, in _select_qt_binding
    QT_BINDING_VERSION = binding_loader(required_modules, optional_modules)
  File "/opt/ros/noetic/lib/python3/dist-packages/python_qt_binding/binding_helper.py", line 158, in _load_pyqt
    _named_optional_import('PyQt5.%s' % module_name)
  File "/opt/ros/noetic/lib/python3/dist-packages/python_qt_binding/binding_helper.py", line 145, in _named_optional_import
    _named_import(name)
  File "/opt/ros/noetic/lib/python3/dist-packages/python_qt_binding/binding_helper.py", line 136, in _named_import
    module = builtins.__import__(name)
ValueError: PyCapsule_GetPointer called with incorrect name

  在网上搜报错原因的时候绝大多数都提到了pyqt5版本问题,版本太新或者不匹配之类的,为此我重新下了四五个版本,都不管用,感觉靠百度和Google已经无法解决问题了,于是开始硬刚,读代码debug。
  问题最终指向的就是/opt/ros/noetic/lib/python3/dist-packages/python_qt_binding/binding_helper.py这个文件,函数_load_pyqt在导入可选模块(optional_modules)时出现了报错,导入过程是对optional_modules列表中的每一项循环导入,因此我在导入的循环中加了个print(module_name),看看是导入哪个module的时候出了事情。最终发现循环停在了导入QtWebKitWidgets模块的时候,查看optional_modules列表,可以看到:

'QtWebEngine',  # Qt 5.6 and higher
'QtWebEngineCore',
'QtWebEngineWidgets',
'QtWebKitWidgets',  # Qt 5.0 - 5.5

  单看注释我感觉QtWebEngineQtWebKitWidgets应该是对应不同版本的同一个东西,由于我的Qt版本比较高,应该是选择QtWebEngine就可以了,于是把QtWebKitWidgets对应那行删了,重新跑了一下,rqt真的可以用了!虽然终端还是有一些报错:

RosPluginProvider.load(qt_gui_cpp/CppPluginProvider) exception raised in __builtin__.__import__(qt_gui_cpp.cpp_plugin_provider, [CppPluginProvider]):
Traceback (most recent call last):
  File "/opt/ros/noetic/lib/python3/dist-packages/rqt_gui/ros_plugin_provider.py", line 79, in load
    module = __builtin__.__import__(
  File "/opt/ros/noetic/lib/python3/dist-packages/qt_gui_cpp/cpp_plugin_provider.py", line 33, in 
    from .cpp_binding_helper import qt_gui_cpp
  File "/opt/ros/noetic/lib/python3/dist-packages/qt_gui_cpp/cpp_binding_helper.py", line 43, in 
    from . import libqt_gui_cpp_sip
ValueError: PyCapsule_GetPointer called with incorrect name

RecursivePluginProvider.discover() loading plugin "qt_gui_cpp/CppPluginProvider" failed:
Traceback (most recent call last):
  File "/opt/ros/noetic/lib/python3/dist-packages/qt_gui/recursive_plugin_provider.py", line 60, in discover
    instance = self._plugin_provider.load(plugin_descriptor.plugin_id(), None)
  File "/opt/ros/noetic/lib/python3/dist-packages/rqt_gui/ros_plugin_provider.py", line 90, in load
    raise e
  File "/opt/ros/noetic/lib/python3/dist-packages/rqt_gui/ros_plugin_provider.py", line 79, in load
    module = __builtin__.__import__(
  File "/opt/ros/noetic/lib/python3/dist-packages/qt_gui_cpp/cpp_plugin_provider.py", line 33, in 
    from .cpp_binding_helper import qt_gui_cpp
  File "/opt/ros/noetic/lib/python3/dist-packages/qt_gui_cpp/cpp_binding_helper.py", line 43, in 
    from . import libqt_gui_cpp_sip
ValueError: PyCapsule_GetPointer called with incorrect name

  不过问题不大,能用就行,试了一下,好像只有rqt_image_view是打不开的,不过我也不是做Qt开发的,只是ROS里需要用到rqt,rviz完全可以替代rqt_image_view的功能,所以问题大致算是解决了。

你可能感兴趣的:(python,ubuntu,开发语言)