我无法在 Spyder IDE 中运行/使用 Mayavi 库。我已经在下面描述了这个问题。任何帮助都会非常有用。(非常感谢您。)
重现问题的步骤:
- 只需在脚本中导入 Mayavi 库(例如使用“import mayavi.mlab as mlab”)并执行脚本就会重现此问题。
- 我在此处包含一个测试代码(请注意,此代码是 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
---------------------------- 错误信息结束 ------------------ --
我的环境如下:
至少在以下两种环境中已观察到此问题:
环境1:
描述:Spyder 和所有其他组件是使用 Pythonxy 发行版 (Py(x,y)-2.7.2.3.exe) 在 Windows 7 32 位机器上安装的。Spyder 版本:2.1.9 Python 版本:2.7.2(32 位) Qt 版本:4.7.4,Windows Mayavi 上的 PyQt4 (API v1) 4.8.6 版本:4.1.0
环境2:
说明:在运行 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 Mayavi 上的 PyQt4 (API v2) 4.9.4 版本:4.2.0
附加信息:
我确信代码很好,因为脚本在“外部”spyder 环境执行时会产生预期的输出。例如,使用 IPython shell。
谢谢你。