Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 奇怪的matplotlib.pyplot导入_Python_Matplotlib - Fatal编程技术网

Python 奇怪的matplotlib.pyplot导入

Python 奇怪的matplotlib.pyplot导入,python,matplotlib,Python,Matplotlib,我在尝试从matplotlib导入模块pyplot时发现了一个非常奇怪的行为。首先它说它不存在,但在导入pylab(另一个matplotlib模块)后,它突然工作了 >>> import matplotlib >>> matplotlib.__version__ '1.2.1' >>> matplotlib.pyplot Traceback (most recent call last): File "<stdin>", li

我在尝试从
matplotlib
导入模块
pyplot
时发现了一个非常奇怪的行为。首先它说它不存在,但在导入
pylab
(另一个
matplotlib
模块)后,它突然工作了

>>> import matplotlib
>>> matplotlib.__version__
'1.2.1'
>>> matplotlib.pyplot
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'pyplot'
>>> import pylab
>>> matplotlib.pyplot
<module 'matplotlib.pyplot' from '/Library/Python/2.7/site-packages/matplotlib/pyplot.pyc'>
导入matplotlib >>>matplotlib.\uuu版本__ '1.2.1' >>>matplotlib.pyplot 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 AttributeError:“模块”对象没有属性“pyplot” >>>进口派拉布 >>>matplotlib.pyplot 其他人在其计算机中有这种行为吗



**这发生在运行Python 2.7的OS X Mountain Lion上。我使用
pip
安装了
matplotlib
。通常,要访问包中的模块,必须导入该模块。您不能只导入包并使用点语法访问模块。只需从matplotlib导入pyplot即可(如果您真的喜欢键入点,也可以导入matplotlib.pyplot)

导入
pylab
后它工作的原因是
pylab
导入
pyplot
,之后
pyplot
作为封装的
matplotlib
的属性可用


基本上,如果您执行
导入包
,您不能期望您能够执行
包.module
。但是,如果您从包导入模块导入包和
,那么您可以执行
包.module
一般来说,要访问包中的模块,您必须导入该模块。您不能只导入包并使用点语法访问模块。只需从matplotlib导入pyplot即可(如果您真的喜欢键入点,也可以导入matplotlib.pyplot)

导入
pylab
后它工作的原因是
pylab
导入
pyplot
,之后
pyplot
作为封装的
matplotlib
的属性可用


基本上,如果您执行
导入包
,您不能期望您能够执行
包.module
。但是,如果您执行
导入包
从包导入模块
,那么您就可以执行
package.module

,这就解决了所有问题。谢谢你,好心的先生(现在,让我们等9分钟吧…)好吧,这回答了所有问题。谢谢好心的先生(现在,让我们等9分钟…)