Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas: AttributeError: 'module' object has no attribute '__version__'

When I try to import pandas into Python I get this error:

>>> 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:

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?

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

Edit2

I wanted to see if there was a different path to the executables ipython and python. So I ran this:

$ python
>>> import sys
>>> print sys.executable 
/Users/me/miniconda2/bin/python

However in IPython, I get this:

$ ipython notebook
>>> import sys
>>> print sys.executable
/usr/local/opt/python/bin/python2.7

Could that be the problem?

like image 864
Chef1075 Avatar asked Oct 19 '25 15:10

Chef1075


3 Answers

Remove (or rename) the file matplotlib.py from your current working directory. It shadows the real library with the same name.

like image 193
Mike Müller Avatar answered Oct 21 '25 04:10

Mike Müller


It worked for me

pip install pyparsing==2.4.7
like image 41
Robin Reni Avatar answered Oct 21 '25 03:10

Robin Reni


Remove (or rename) the file matplotlib.py from your current working directory. It shadows the real library with the same name.

like image 29
Mike Müller Avatar answered Oct 21 '25 04:10

Mike Müller