ValueError: cannot set toolkit to wx because it has already been set to qt4

落花浮王杯 提交于 2019-11-30 09:51:48

Don't know, whether my answer is relevant now, but this helped me: I have PyQt4 on my machine, but I've installed wxPython for Mayavi, so they were conflicting. I've removed wxPython and now it works just perfect.

imranal

There is a post on SO :

How to get MayaVi2 to default to/use Qt rather than wx?

where it shows how you can set qt4, without having to uninstall wxPython (as the other answer suggests) :

export ETS_TOOLKIT=qt4

I found out about it among the issues section on the Mayavi github : Issue 265

Dude, maybe you made the same silly mistake as I did, LOL.

Same Error

I was trying to use WXAgg as backend for matplotlib and traitsui but I got a RuntimeError: Importing from wx backend after selecting qt4 backend. The import part is as follows:

import matplotlib
# We want matplotlib to use a wxPython backend
matplotlib.use('WXAgg')
import wx

from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from traits.api import Instance
from traitsui.wx.editor import Editor
from traitsui.wx.basic_editor_factory import BasicEditorFactory

Then I tried to manually change the backend with following codes:

from traits.etsconfig.api import ETSConfig
ETSConfig.toolkit = 'wx'

Guess what, I got the same ValueError: cannot set toolkit to wx because it has already been set to qt4 as you do.

Check Before You Go

After hours of searching and debugging, I almost gave up until suddenly I recall that I have set this variable system wide once. How stupid I am not to follow this hint and check ETS_TOOLKIT!

Anybody who come across this error again, pls check you system settings with echo $ETS_TOOLKIT on Linux or echo %ETS_TOOLKIT% on Windows. If it says qt4, then it's your fault causing this error.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!