我无法在Spyder IDE中运行/使用Mayavi库。我已经描述了下面的问题。任何帮助都将非常有用。 (非常感谢你提前。)
重现问题的步骤:
from numpy import sin, cos, mgrid
import mayavi.mlab as mmlab
def f(x,y):
return sin(x + y) + sin(2*x - y) + cos(3*x + 4*y)
x,y = mgrid[-7.:7.05:0.01, -5.:5.05:0.05]
z = f(x,y)
s = mmlab.contour_surf(x,y,z)
mmlab.show()
预期输出和错误:
预期输出:带有数字的Mayavi数字窗口。 我所看到的是:在控制台窗口中出现以下值错误(我包括完整的消息序列):
--------------------------错误信息的开头-------------- ----
Traceback (most recent call last):
File "C:\PROGRAMSANDEXPERIMENTS\PYTHON\MayaviScripts\Learning\testMayavi.py", line 2, in <module>
import mayavi.mlab as mmlab
File "C:\Python27\lib\site-packages\mayavi\mlab.py", line 27, in <module>
from mayavi.tools.camera import view, roll, yaw, pitch, move
File "C:\Python27\lib\site-packages\mayavi\tools\camera.py", line 25, in <module>
from engine_manager import get_engine
File "C:\Python27\lib\site-packages\mayavi\tools\engine_manager.py", line 12, in <module>
from mayavi.preferences.api import preference_manager
File "C:\Python27\lib\site-packages\mayavi\preferences\api.py", line 4, in <module>
from preference_manager import preference_manager
File "C:\Python27\lib\site-packages\mayavi\preferences\preference_manager.py", line 29, in <module>
from traitsui.api import View, Group, Item
File "C:\Python27\lib\site-packages\traitsui\api.py", line 35, in <module>
from .editors.api import (ArrayEditor, BooleanEditor, ButtonEditor,
File "C:\Python27\lib\site-packages\traitsui\editors\__init__.py", line 22, in <module>
from .api import (toolkit, ArrayEditor, BooleanEditor, ButtonEditor,
File "C:\Python27\lib\site-packages\traitsui\editors\api.py", line 10, in <module>
from .code_editor import CodeEditor
File "C:\Python27\lib\site-packages\traitsui\editors\code_editor.py", line 36, in <module>
class ToolkitEditorFactory ( EditorFactory ):
File "C:\Python27\lib\site-packages\traitsui\editors\code_editor.py", line 48, in ToolkitEditorFactory
mark_color = Color( 0xECE9D8 )
File "C:\Python27\lib\site-packages\traits\traits.py", line 487, in __call__
return self.maker_function( *args, **metadata )
File "C:\Python27\lib\site-packages\traits\traits.py", line 1183, in Color
return ColorTrait( *args, **metadata )
File "C:\Python27\lib\site-packages\traitsui\toolkit_traits.py", line 7, in ColorTrait
return toolkit().color_trait( *args, **traits )
File "C:\Python27\lib\site-packages\traitsui\toolkit.py", line 109, in toolkit
_toolkit = _import_toolkit(ETSConfig.toolkit)
File "C:\Python27\lib\site-packages\traitsui\toolkit.py", line 51, in _import_toolkit
return __import__( name, globals=globals(), level=1 ).toolkit
File "C:\Python27\lib\site-packages\traitsui\qt4\__init__.py", line 18, in <module>
import pyface.qt
File "C:\Python27\lib\site-packages\pyface\qt\__init__.py", line 35, in <module>
prepare_pyqt4()
File "C:\Python27\lib\site-packages\pyface\qt\__init__.py", line 17, in prepare_pyqt4
sip.setapi('QString', 2)
ValueError: API 'QString' has already been set to version 1
----------------------------结束错误消息------------ --------
我的环境如下:
至少在以下两种环境中已经发现了这个问题:
描述:在Windows 7,32位机器上使用Pythonxy发行版(Py(x,y)-2.7.2.3.exe)安装Spyder和所有其他组件。 Spyder版本:2.1.9 Python版本:2.7.2(32位) Qt版本:4.7.4,Windows上的PyQt4(API v1)4.8.6 Mayavi版本:4.1.0
描述:在运行64位Windows 7的单独机器上,我安装了64位版本的Enthought EPD发行版。所以它运行的是2.7.3(x64)版本的Python发行版。由于EPD包不包括Spyder,我在安装PyQt GPLv4.9.4后手动安装Spyder。
Spyder版本:2.1.11
Python版本:2.7.3(64位)
Qt版本:4.8.2,Windows上的PyQt4(API v2)4.9.4
Mayavi版本:4.2.0
其他信息:
我确信代码很好,因为脚本在执行“外部”spyder环境时会产生预期的输出。例如,使用IPython shell。
谢谢。
答案 0 :(得分:7)
感谢Avaris的回复。
我现在有一个解决方案(我不确定它是“修复”)。我在Tools->Preferences->Console->External Modules->Enthought Tool Suite->ETS_TOOLKIT
中修改了以下设置:从Qt4
更改为wx
。
更改此设置后,我可以直接从Spyder中使用Mayavi库和Mayavi图执行代码。
答案 1 :(得分:3)
对于linux用户,可以参考this issues中imranal
的答案。
只需将export ETS_TOOLKIT=qt4
添加到~/.bashrc
中的新行即可。
不要忘记source
~/.bashrc
文件!
答案 2 :(得分:1)