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'")]
18
  • 1
    Which version of matplotlib is it ? Commented Nov 22, 2016 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 stackoverflow.com/questions/21473600/matplotlib-version Commented Nov 22, 2016 at 14:44
  • Try this : from matplotlib.style import use use('ggplot') Commented Nov 22, 2016 at 14:46
  • You should update your version of matplotlib : stackoverflow.com/questions/27204646/… Commented Nov 22, 2016 at 14:53
  • 1
    Try pip2 install -U matplotlib to upgrade your package Commented Nov 22, 2016 at 15:12

1 Answer 1

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

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

Comments

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.