当“将matplotlib.pyplot导入为plt"时出现错误. [英] Error when "import matplotlib.pyplot as plt"
问题描述
我是python的新手.因此,我的问题可能太简单而无法解决.但是我不能.请帮我! 我使用"plt"没有任何问题,但是在导入时它突然显示错误消息并且不起作用.请参阅下面的内容.
I am very new to python. So, my problem might be too simple to be solved. But I cannot. Please help me! I did not have any problem to use "plt", but it suddenly shows error message and does not work, when I import it. Please see the below.
>>> import matplotlib
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.6/site-packages/matplotlib/pyplot.py", line 6, in <module>
from matplotlib.figure import Figure, figaspect
File "/usr/lib64/python2.6/site-packages/matplotlib/figure.py", line 18, in <module>
from axes import Axes, SubplotBase, subplot_class_factory
File "/usr/lib64/python2.6/site-packages/matplotlib/axes.py", line 2, in <module>
import math, sys, warnings, datetime, new
File "new.py", line 12, in <module>
import matplotlib.pyplot as plt
AttributeError: 'module' object has no attribute 'pyplot'
此软件包突然损坏了?因此,我尝试按以下方式安装.我使用ubuntu.
This package is suddenly corrupted? So, I tried to install as below.I use ubuntu.
In [1]: sudo apt-get install python-matplotlib
File "<ipython-input-1-2400ac877ebd>", line 1
sudo apt-get install python-matplotlib
^
SyntaxError: invalid syntax
如果我需要重新安装,请给我非常详细的说明. 提前非常感谢您.
If I need to reinstall, please give me very detailed instruction how to do it. Thank you very much in advance.
推荐答案
尝试在终端中键入sudo apt-get install python-matplotlib
.在您的消息中,您在ipython控制台中键入了它.这是一个bash命令,而不是python命令.
Try to type sudo apt-get install python-matplotlib
in a terminal. In your message you typed it in ipython console. This is a bash command, not a python one.
您需要先退出ipython.为此,请使用Ctrl + D
You need to quit ipython before. For that use Ctrl + D
这篇关于当“将matplotlib.pyplot导入为plt"时出现错误.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!