简体   繁体   English

matplotlib没有使用qt4agg后端打开pyplot.show()的情节而找不到sip

[英]matplotlib doesn't open plot with pyplot.show() using qt4agg backend and couldn't find sip

I have a very similar question to this one: matplotlib does not show my drawings although I call pyplot.show() 我对此问题有一个非常类似的问题: 尽管我调用了pyplot.show(),matplotlib也没有显示我的绘图

I am using: Ubuntu 12.04; 我正在使用:Ubuntu 12.04; Python 3.4.1; Python 3.4.1; Pycharm 3.4.1 Pycharm 3.4.1

So, I run the following code in pyCharm using 3.4.1 interpreter and plot doesn't appear: 所以,我使用3.4.1解释器在pyCharm中运行以下代码,并且没有出现图:

import matplotlib.pyplot as p 
p.plot(range(20), range(20))
p.show()

Then I thought it could be something with pycharm, therefore I have tried the same in the terminal. 然后我认为它可能是pycharm的东西,因此我在终端尝试了相同的东西。 However, plot didn't appear too. 但是,情节也没有出现。

However, since Ubuntu is with built-in Python 2.7, I have tried the same on terminal, then on pycharm and plot did appear. 但是,由于Ubuntu内置Python 2.7,我在终端上尝试了相同的功能,然后在pycharm和plot上出现了。

I have found out that backend in matplotlibrc file should be changed. 我发现matplotlibrc文件中的后端应该被更改。 I googled, that qt4agg backend should be used. 我用谷歌搜索,应该使用qt4agg后端。 After changing it and trying to import matplotlib.pyplot I get the following 更改它并尝试导入matplotlib.pyplot后,我得到以下内容

import matplotlib.pyplot as p
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/local/lib/python3.4/dist-packages/matplotlib/pyplot.py", line 98, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/usr/local/lib/python3.4/dist-packages/matplotlib/backends/__init__.py", line 28, in pylab_setup
globals(),locals(),[backend_name],0)
File "/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_qt4agg.py", line 13, in <module>
from .backend_qt4 import QtCore, QtGui, FigureManagerQT, FigureCanvasQT,\
File "/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_qt4.py", line 25, in <module>
from .qt4_compat import QtCore, QtGui, _getSaveFileName, __version__
File "/usr/local/lib/python3.4/dist-packages/matplotlib/backends/qt4_compat.py", line 36, in <module>
import sip
ImportError: No module named 'sip'

Therefore, I installed sip using 因此,我安装了sip使用

 sudo apt-get install python3-sip

and the same error appears. 并出现相同的错误。

I am trying to find out whats wrong with SIP. 我试图找出SIP的错误。 However, I am kinda confused, any help would be appreciated. 但是,我有点困惑,任何帮助将不胜感激。 Thanks 谢谢

Alright, so after a lot of effort, I finally managed to do it. 好吧,经过很多努力,我终于成功了。

Firstly, I had probably, three or four different python versions in my computer: 2.7 as ubuntu default, 3.2, 3.4.0 and 3.4.1. 首先,我的计算机可能有三到四种不同的python版本:2.7作为ubuntu默认版本,3.2,3.4.0和3.4.1。 Each of them had different versions of matplotlib (majority 1.3.1). 他们每个人都有不同版本的matplotlib(多数为1.3.1)。 So, firstly I cleaned up useless python versions (3.2, 3.4). 所以,首先我清理了无用的python版本(3.2,3.4)。

Secondly, I removed all available matplotlib directories. 其次,我删除了所有可用的matplotlib目录。 I used matplotlib documentation to determine which folders should be removed to fully remove it. 我使用matplotlib文档来确定应删除哪些文件夹以完全删除它。 ( http://matplotlib.org/contents.html ) http://matplotlib.org/contents.html

After that, I cloned newest matplotlib version from git ( http://matplotlib.org/faq/installing_faq.html#install-from-git ) and installed it. 之后,我从git( http://matplotlib.org/faq/installing_faq.html#install-from-git )克隆了最新的matplotlib版本并安装了它。 And this point matplotlib version is 1.4. 而这一点matplotlib版本是1.4。 Then I tried to reproduce my first example again and it worked. 然后我尝试再次重现我的第一个例子并且它有效。 No backend was changed. 没有后端被改变。

Thus, clean removal and newest version should do the trick. 因此,干净的删除和最新版本应该做到这一点。

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

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