0

I am using a Mac,

I try to use the ggplot as follow

import matplotlib.pyplot as plt
plt.style.use('ggplot')

but I am always getting an error like

File "/Users/Desktop/code.py", line 4, in <module>
    plt.style.use('ggplot')
AttributeError: 'module' object has no attribute 'style'

I have been checking to find a solution but I don't know where i am making a mistake. Any comment ?

As mentioned blow, I must upgrade the matplotlibhowever, I am getting error My python version is 2.7 so I tried this

pip2 install matplotlib

and here are the errors

Requirement already satisfied: matplotlib in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Requirement already satisfied: numpy>=1.5 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib)
Requirement already satisfied: python-dateutil in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib)
Requirement already satisfied: tornado in /Library/Python/2.7/site-packages (from matplotlib)
Requirement already satisfied: pyparsing>=1.5.6 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib)
Requirement already satisfied: nose in /Library/Python/2.7/site-packages (from matplotlib)
Requirement already satisfied: singledispatch in /Library/Python/2.7/site-packages/singledispatch-3.4.0.3-py2.7.egg (from tornado->matplotlib)
Requirement already satisfied: certifi in /Library/Python/2.7/site-packages (from tornado->matplotlib)
Requirement already satisfied: backports_abc>=0.4 in /Library/Python/2.7/site-packages (from tornado->matplotlib)
Requirement already satisfied: six in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from singledispatch->tornado->matplotlib)

Or I tried

sudo port install py27-pip

and here are the errors

Password:
Error: Current platform "darwin 16" does not match expected platform "darwin 15"
Error: If you upgraded your OS, please follow the migration instructions: https://trac.macports.org/wiki/Migration
OS platform mismatch
    while executing
"mportinit ui_options global_options global_variations"
Error: /opt/local/bin/port: Failed to initialize MacPorts, OS platform mismatch

or I tried this

python get-pip.py
#Requirement already up-to-date: pip in /Library/Python/2.7/site-packages

then

pip install matplotlib

the errors are the following

Requirement already satisfied: matplotlib in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Requirement already satisfied: numpy>=1.5 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib)
Requirement already satisfied: python-dateutil in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib)
Requirement already satisfied: tornado in /Library/Python/2.7/site-packages (from matplotlib)
Requirement already satisfied: pyparsing>=1.5.6 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib)
Requirement already satisfied: nose in /Library/Python/2.7/site-packages (from matplotlib)
Requirement already satisfied: singledispatch in /Library/Python/2.7/site-packages/singledispatch-3.4.0.3-py2.7.egg (from tornado->matplotlib)
Requirement already satisfied: certifi in /Library/Python/2.7/site-packages (from tornado->matplotlib)
Requirement already satisfied: backports_abc>=0.4 in /Library/Python/2.7/site-packages (from tornado->matplotlib)
Requirement already satisfied: six in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from singledispatch->tornado->matplotlib)


pip2 install -U matplotlib

or

sudo pip2 install -U matplotlib

It gives me a lot of error just few lines at the bottom blew

('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pytz/zoneinfo', '/var/folders/0y/736q6sd901z27bmpx9nwn_p40000gn/T/pip-r5YiwW-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pytz/zoneinfo', "[Errno 1] Operation not permitted: '/var/folders/0y/736q6sd901z27bmpx9nwn_p40000gn/T/pip-r5YiwW-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pytz/zoneinfo'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pytz', '/var/folders/0y/736q6sd901z27bmpx9nwn_p40000gn/T/pip-r5YiwW-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pytz', "[Errno 1] Operation not permitted: '/var/folders/0y/736q6sd901z27bmpx9nwn_p40000gn/T/pip-r5YiwW-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pytz'")]

The same if I do with sudo

"[Errno 1] Operation not permitted: '/tmp/pip-5PMqIK-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pytz'")]
Chr
  • 875
  • 1
  • 10
  • 27
  • 1
    Which version of matplotlib is it ? – Chr Nov 22 '16 at 14:36
  • @C.Dlp to be honest , I don't know , I don't know how to check it neither I read this one but did not help me to know which versions it is http://stackoverflow.com/questions/21473600/matplotlib-version – Learner Algorithm Nov 22 '16 at 14:44
  • Try this : `from matplotlib.style import use` `use('ggplot')` – Chr Nov 22 '16 at 14:46
  • You should update your version of matplotlib : http://stackoverflow.com/questions/27204646/matplotlib-pyplot-has-no-attribute-style – Chr Nov 22 '16 at 14:53
  • run `python -c "import matplotlib.pyplot as plt; print(dir(plt))"` and verify that you can see `style` in the diplayed list. – ettanany Nov 22 '16 at 14:56
  • @ettanany great, I did not see the `style`so I must install it again? actually I am trying to install it by different ways introduced here http://matplotlib.org/faq/installing_faq.html#install-osx-binaries which I am getting error . would you please give me a solution as an answer to upgrade it? I would accept your solution – Learner Algorithm Nov 22 '16 at 15:05
  • @C.Dlp the problem is that I cannot upgrade or install `matplotlib`again. look at above – Learner Algorithm Nov 22 '16 at 15:08
  • 1
    Try `pip2 install -U matplotlib` to upgrade your package – ettanany Nov 22 '16 at 15:12
  • You need to post the last lines which should contain some information about the error – ettanany Nov 22 '16 at 15:21
  • @ettanany I added above – Learner Algorithm Nov 22 '16 at 15:31
  • try `sudo pip2 install -U matplotlib --ignore-installed six` –  Nov 22 '16 at 15:55
  • @ettanany @Learner now I get this error `/Library/Python/2.7/site-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment. warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')`any thought how to solve it, – Learner Algorithm Nov 22 '16 at 16:08
  • Try to uninstall matplotlib `pip uninstall matplotlib` and then re-install with correct version `pip install matplotlib==1.4.3` – Chr Nov 22 '16 at 16:11
  • @C.Dlp I get this error `"[Errno 1] Operation not permitted: '/tmp/pip-hnzCP4-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib'")]` – Learner Algorithm Nov 22 '16 at 16:19
  • Do you use a virtualenv ? In this case delete it and re-install it. – Chr Nov 22 '16 at 16:22
  • @C.Dlp I just installed `virtualenv`then `sudo pip uninstall matplotlib` then `sudo pip install matplotlib==1.4.3` which I always get error like `Operation not permitted: '/tmp/pip-VDR0Gs-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib'")]` – Learner Algorithm Nov 22 '16 at 16:26
  • And with `sudo pip install --ignore-installed matplotlib==1.4.3` ? – Chr Nov 22 '16 at 16:30
  • @C.Dlp I get this error then `OSError: [Errno 1] Operation not permitted: '/System/Library/Frameworks/Python.framework/Versions/2.7/man'` – Learner Algorithm Nov 22 '16 at 16:33

1 Answers1

2

One way is to do

sudo pip2 install -U matplotlib --ignore-installed six

You must use --ignore-installed six because of the fact that OS ships with six 1.4.1 installed and if one tries to uninstall it (because awscli depends on botocore, botocore depends on python-dateutil, and python-dateutil depends on six >= 1.5) it doesn't have permission to do so because System Integrity Protection doesn't allow even root to modify those directories.

This is highlighted here https://github.com/pypa/pip/issues/3165

After you do this, you can check the version of your matplotlibas

python -c 'import matplotlib; print matplotlib.__version__'

If you get the error you mentioned as

/usr/local/lib/python2.7/dist-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
  warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')

, then it is easy to solve it

open terminal

Then write python

Then

>>> import matplotlib as mpl
>>> mpl.get_configdir()

Once you know the path, go to the finder -----> Go There search for the folder and remove fontList

Then run your program again, you will get the warning once more and it is solved. Further info, can be found here too for the second part matplotlib taking time when being imported

Community
  • 1
  • 1