ImportError: Could not import backend for traitsui. Make sure you have a suitable UI toolkit like

问题

在运行mayavi时会出现如下问题:

Traceback (most recent call last):
  File "E:/Aworkspace/PycharmProjects/untitled/sss.py", line 36, in <module>
    s = mlab.mesh(x,y,z)
  File "E:\softinstall\Anaconda3\lib\site-packages\mayavi\tools\helper_functions.py", line 37, in the_function
    return pipeline(*args, **kwargs)
  File "E:\softinstall\Anaconda3\lib\site-packages\mayavi\tools\helper_functions.py", line 77, in __call__
    scene = tools.gcf().scene
  File "E:\softinstall\Anaconda3\lib\site-packages\mayavi\tools\figure.py", line 114, in gcf
    engine = get_engine()
  File "E:\softinstall\Anaconda3\lib\site-packages\mayavi\tools\engine_manager.py", line 92, in get_engine
    return self.new_engine()
  File "E:\softinstall\Anaconda3\lib\site-packages\mayavi\tools\engine_manager.py", line 137, in new_engine
    check_backend()
  File "E:\softinstall\Anaconda3\lib\site-packages\mayavi\tools\engine_manager.py", line 40, in check_backend
    raise ImportError(msg)
ImportError: Could not import backend for traitsui.  Make sure you
        have a suitable UI toolkit like PyQt/PySide or wxPython
        installed.

问题原因

在Python3.x环境下在安装mayavi时,想要运行成功,则需要PyQt、PySide或者wxPython。
据说在Python3.7环境下,PyQt5、wxPython和mayavi不兼容。
本人测试了,安装了PyQt5后运行代码还是会出现上面的错误,
而安装了wxPython则也会出现下面错误。

traits.trait_errors.TraitError: The '_position' trait of a MayaviViewer instance must be a
 tuple of the form: (a value of class 'int', a value of class 'int'), but a value of 
 wx.Point(900, 730) <class 'wx._core.Point'> was specified.

因此,本人想要安装PySide来解决上面问题。

解决方法

安装对应版本的PySide即可。

发布了173 篇原创文章 · 获赞 48 · 访问量 11万+

猜你喜欢

转载自blog.csdn.net/zyb228107/article/details/104273046
今日推荐