简体   繁体   English

%matplotlib qt错误结束-调用PyQt5而不是PyQt4

[英]%matplotlib qt ends in error - calls PyQt5 instead of PyQt4

I am trying to open graphics in a new window using the command %matplotlib qt in ipython/spyder, but it shows following error 我正在尝试在ipython / spyder中使用命令%matplotlib qt在新窗口中打开图形,但显示以下错误

%matplotlib qt
Traceback (most recent call last):

File "<ipython-input-1-4460ac8d7abe>", line 1, in <module>
get_ipython().magic(u'matplotlib qt')

File "/usr/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 2160, in magic
return self.run_line_magic(magic_name, magic_arg_s)

 File "/usr/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 2081, in run_line_magic
result = fn(*args,**kwargs)

 File "<decorator-gen-105>", line 2, in matplotlib

 File "/usr/lib/python2.7/site-packages/IPython/core/magic.py", line 188, in <lambda>
call = lambda f, *a, **k: f(*a, **k)

 File "/usr/lib/python2.7/site-packages/IPython/core/magics/pylab.py", line 100, in matplotlib
gui, backend = self.shell.enable_matplotlib(args.gui)

 File "/usr/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 2950, in enable_matplotlib
pt.activate_matplotlib(backend)

 File "/usr/lib/python2.7/site-packages/IPython/core/pylabtools.py", line 309, in activate_matplotlib
matplotlib.pyplot.switch_backend(backend)

 File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 231, in switch_backend
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()

 File "/usr/lib64/python2.7/site-packages/matplotlib/backends/__init__.py", line 60, in pylab_setup
[backend_name], 0)

 File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_qt5agg.py", line 16, in <module>
from .backend_qt5 import (

 File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_qt5.py", line 18, in <module>
import matplotlib.backends.qt_editor.figureoptions as figureoptions

 File "/usr/lib64/python2.7/site-packages/matplotlib/backends/qt_editor/figureoptions.py", line 20, in <module>
import matplotlib.backends.qt_editor.formlayout as formlayout

 File "/usr/lib64/python2.7/site-packages/matplotlib/backends/qt_editor/formlayout.py", line 56, in <module>
from matplotlib.backends.qt_compat import QtGui, QtWidgets, QtCore

 File "/usr/lib64/python2.7/site-packages/matplotlib/backends/qt_compat.py", line 137, in <module>
from PyQt5 import QtCore, QtGui, QtWidgets

ImportError: No module named PyQt5

I didn't install PyQt5, but installed PyQt4 in centos 7.4. 我没有安装PyQt5,但是在centos 7.4中安装了PyQt4。 Also modified the file matplotlibrc (/usr/lib64/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc) file to change backend and as follows: 还修改了文件matplotlibrc(/usr/lib64/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc)文件以更改后端,如下所示:

 # If you omit this parameter, it will always default to "Agg", which is a
 # non-interactive backend.
 backend      : Qt4Agg

 # If you are using the Qt4Agg backend, you can choose here
 # to use the PyQt4 bindings or the newer PySide bindings to
 # the underlying Qt4 toolkit.
 backend.qt4 : PyQt4        # PyQt4 | PySide

But still it calls PyQt5. 但它仍然称为PyQt5。 After running the command "%matplotlib qt", the back-end changed back into Qt5Agg (print matplotlib.rcParams['backend']), even I wrote Qt4Agg in matplotlibrc. 运行命令“%matplotlib qt”后,即使我在matplotlibrc中编写了Qt4Agg,后端也变回了Qt5Agg(打印matplotlib.rcParams ['backend'])。

Note:- I tried "%matplotlib qt4" also 注意:-我也尝试过“%matplotlib qt4”

Warning: Cannot change to a different GUI toolkit: qt4. Using qt instead.

Please refer to the IPython 5 configuration page . 请参考IPython 5配置页面 I don't have a IPython 5 and Python 2.7 set up so I cannot give you the exact configuration code. 我没有设置IPython 5和Python 2.7,所以我无法为您提供确切的配置代码。 But inorder to make IPython use Qt4 you will have to follow the following steps: 但是为了使IPython使用Qt4,您必须遵循以下步骤:

  1. Create configuration files like giving in this page. 创建配置文件,例如在页面中提供。
  2. The list of configurations that you will need to change are given on this page. 页面上提供了您需要更改的配置列表。 Just go through the list and wherever you see an option between qt4 and qt5 just set those values to qt4 in the config files that you created in step 1. 只需浏览列表,然后在任何地方看到qt4和qt5之间的选项,只需在您在步骤1中创建的配置文件中将这些值设置为qt4。

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM