简体   繁体   English

matplotlib不导入PyQt4,PyQt5或PySide

[英]matplotlib does not import PyQt4, PyQt5 or PySide

I'm using Canopy 2.1.3 distribution (on Ubuntu 16.04) which as you may know contains the matplotlib package. 我正在使用Canopy 2.1.3发行版(在Ubuntu 16.04上),您可能知道它包含matplotlib包。 Simply running in the Canopy's shell import matplotlib.pyplot as plt gives me 只需在Canopy的shell中运行import matplotlib.pyplot as plt给我的那样

ImportError: Matplotlib qt-based backends require an external PyQt4, PyQt5, or PySide package to be installed, but it was not found. ImportError:基于matplotlib qt的后端需要安装外部PyQt4,PyQt5或PySide包,但未找到它。

I have installed all of the three packages with Synaptic but the problem persists. 我已经使用Synaptic安装了所有这三个软件包,但问题仍然存在。 Could this be related to environment variables? 这可能与环境变量有关吗? Or, could it be because Canopy's Python 3.5 and Ubuntu's Python 2.7 are conflicting? 或者,是不是因为Canopy的Python 3.5和Ubuntu的Python 2.7存在冲突?

EDIT: I have finally used the PyQt by installing it from the Canopy's package manager. 编辑:我最终通过从Canopy的软件包管理器安装它来使用PyQt。

It is likely that the default backend for matplotlib.pyplot is set to qt . matplotlib.pyplot的默认后端可能设置为qt
I have very little experience with canopy, but it should be possible to change the default to another back end; 我对冠层的经验很少,但应该可以将默认值更改为另一个后端; maybe someone else will be able to tell you how, or you can find it by yourself. 也许其他人可以告诉你如何,或者你可以自己找到它。

In the meantime, you can try to add this above all other matplotlib imports: 在此期间,您可以尝试将其添加到所有其他matplotlib导入之上:

import matplotlib
matplotlib.use('TkAgg')

From the user guide: 来自用户指南:

Known Issue: In Canopy running Python 3, GUI backend must be explicitly set 已知问题:在运行Python 3的Canopy中,必须明确设置GUI后端

If you ask matplotlib to display a plot, or otherwise run Python code that creates a GUI window, by default you will get an error traceback ending with: ImportError: No module named 'PyQt4' 如果你要求matplotlib显示一个图,或者运行创建GUI窗口的Python代码,默认情况下你会得到一个错误回溯,结尾为:ImportError:没有名为'PyQt4'的模块

The solutions are to install PyQt (which is GPL-licensed) in the Canopy Package Manager, or to use the Canopy Preference menu's Python tab to specify the TK PyLab backend for creating GUIs. 解决方案是在Canopy包管理器中安装PyQt(GPL许可),或使用Canopy Preference菜单的Python选项卡指定用于创建GUI的TK PyLab后端。 For details, see “Python 3 in Canopy 2 - 'No module named PyQt4' error” 有关详细信息,请参阅“Canopy 2中的Python 3 - '没有名为PyQt4的模块'错误”

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

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