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即可。

發佈了174 篇原創文章 · 獲贊 53 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章