4

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?

3
  • 1
    @cel removed, thanks Commented Jan 2, 2016 at 9:45
  • 1
    Please consider adding the output of pip list |grep matplotlib and conda list matplotlib to your question. Commented Jan 2, 2016 at 9:49
  • I've update the question with your request @cel Commented Jan 2, 2016 at 17:52

4 Answers 4

13

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

Sign up to request clarification or add additional context in comments.

4 Comments

remove it from "/Users/me/miniconda2/lib/python2.7/..." ?
I do not have a matplotlib.py in my working dir... What do you mean exactly?
@TheUnfunCat Do you have exactly the same exception as given in the question? If not, you might need a different solution.
Not exactly, I guess this has happened for a different reason. Thanks anyways.
1

It worked for me

pip install pyparsing==2.4.7

Comments

0

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.

Comments

0

I had the same problem.

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

Did not have matplotlib.py in my project.

Still had this error:

    >>> import pandas
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\Python36\lib\site-packages\pandas\__init__.py", line 55, in <module>
    from pandas.core.api import (
  File "C:\Program Files\Python36\lib\site-packages\pandas\core\api.py", line 24, in <module>
    from pandas.core.groupby import Grouper, NamedAgg
  File "C:\Program Files\Python36\lib\site-packages\pandas\core\groupby\__init__.py", line 1, in <module>
    from pandas.core.groupby.generic import (  # noqa: F401
  File "C:\Program Files\Python36\lib\site-packages\pandas\core\groupby\generic.py", line 44, in <module>
    from pandas.core.frame import DataFrame
  File "C:\Program Files\Python36\lib\site-packages\pandas\core\frame.py", line 115, in <module>
    from pandas.core.series import Series
  File "C:\Program Files\Python36\lib\site-packages\pandas\core\series.py", line 84, in <module>
    import pandas.plotting
  File "C:\Program Files\Python36\lib\site-packages\pandas\plotting\__init__.py", line 59, in <module>
    from pandas.plotting._core import (
  File "C:\Program Files\Python36\lib\site-packages\pandas\plotting\_core.py", line 17, in <module>
    import pandas.plotting._matplotlib  # noqa
  File "C:\Program Files\Python36\lib\site-packages\pandas\plotting\_matplotlib\__init__.py", line 3, in <module>
    from pandas.plotting._matplotlib.boxplot import (
  File "C:\Program Files\Python36\lib\site-packages\pandas\plotting\_matplotlib\boxplot.py", line 4, in <module>
    from matplotlib.artist import setp
  File "C:\Program Files\Python36\lib\site-packages\matplotlib\__init__.py", line 107, in <module>
    from . import cbook, rcsetup
  File "C:\Program Files\Python36\lib\site-packages\matplotlib\rcsetup.py", line 28, in <module>
    from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
  File "C:\Program Files\Python36\lib\site-packages\matplotlib\fontconfig_pattern.py", line 15, in <module>
    from pyparsing import (Literal, ZeroOrMore, Optional, Regex, StringEnd,
  File "C:\Program Files\Python36\lib\site-packages\pyparsing\__init__.py", line 130, in <module>
    __version__ = __version_info__.__version__
AttributeError: 'version_info' object has no attribute '__version__'

I uninstalled matplotlib which solved the problem for me. Since in the current project I did not use them.

I created a new Python 3.8 environment for the other project that uses matplotlib. This worked as well.

At some point I needed matplotlib in Python 3.6 so i reinstalled it. The error again occurred.

I assume matplotlib does not install pyparsing along with it in Python 3.6 environment.

pip install pyparsing==2.4.7

This did the trick for me.

1 Comment

Uninstall matplotlib, while OP accidentally had a py file named matplotlib they shouldn't have named like that, doesn't this solution seem a bit harsch?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.