Pandas: AttributeError: 'module' 对象没有属性 '__version__'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34564249/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pandas: AttributeError: 'module' object has no attribute '__version__'
提问by Chef1075
When I try to import pandas into Python I get this error:
当我尝试将 Pandas 导入 Python 时,出现此错误:
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/robertdefilippi/miniconda2/lib/python2.7/site-packages/pandas/__init__.py", line 44, in <module>
from pandas.core.api import *
File "/Users/robertdefilippi/miniconda2/lib/python2.7/site-packages/pandas/core/api.py", line 9, in <module>
from pandas.core.groupby import Grouper
File "/Users/robertdefilippi/miniconda2/lib/python2.7/site-packages/pandas/core/groupby.py", line 17, in <module>
from pandas.core.frame import DataFrame
File "/Users/robertdefilippi/miniconda2/lib/python2.7/site-packages/pandas/core/frame.py", line 41, in <module>
from pandas.core.series import Series
File "/Users/robertdefilippi/miniconda2/lib/python2.7/site-packages/pandas/core/series.py", line 2909, in <module>
import pandas.tools.plotting as _gfx
File "/Users/robertdefilippi/miniconda2/lib/python2.7/site-packages/pandas/tools/plotting.py", line 135, in <module>
if _mpl_ge_1_5_0():
File "/Users/robertdefilippi/miniconda2/lib/python2.7/site-packages/pandas/tools/plotting.py", line 130, in _mpl_ge_1_5_0
return (matplotlib.__version__ >= LooseVersion('1.5')
AttributeError: 'module' object has no attribute '__version__'
But when I check if pandas is installed:
但是当我检查是否安装了Pandas时:
me$ conda install pandas
Fetching package metadata: ....
Solving package specifications: .....................
# All requested packages already installed.
# packages in environment at /Users/me/miniconda2:
#
pandas 0.17.1 np110py27_0
So I don't know what is wrong? What is going on with my pandas?
所以我不知道有什么问题?我的Pandas怎么了?
Edit
编辑
$ pip list |grep matplotlib
$ conda list matplotlib
# packages in environment at /Users/me/miniconda2:
#
matplotlib 1.5.0 np110py27_0
For some reason there was no output to pip list |grep matplotlib
由于某种原因没有输出 pip list |grep matplotlib
Edit2
编辑2
I wanted to see if there was a different path to the executables ipython
and python
. So I ran this:
我想看看可执行文件ipython
和python
. 所以我运行了这个:
$ python
>>> import sys
>>> print sys.executable
/Users/me/miniconda2/bin/python
However in IPython, I get this:
但是在 IPython 中,我得到了这个:
$ ipython notebook
>>> import sys
>>> print sys.executable
/usr/local/opt/python/bin/python2.7
Could that be the problem?
这可能是问题吗?
回答by Mike Müller
Remove (or rename) the file matplotlib.py
from your current working directory. It shadows the real library with the same name.
matplotlib.py
从当前工作目录中删除(或重命名)文件。它隐藏了具有相同名称的真实图书馆。
回答by Lee Ran
I have a simple solution,delete your __init__.pyc
and __init__.py
files in your project dictionary. because i encounter the problem too,I have been solve it perfectly use this method.
我有一个简单的解决方案,删除您的项目字典中的__init__.pyc
和__init__.py
文件。因为我也遇到了这个问题,用这个方法我已经完美解决了。