Spyder: Error during matplotlib automatic import

Created on 16 Oct 2015  路  8Comments  路  Source: spyder-ide/spyder

When using scientifi_startup in a simple python console (ipython not working see #2770), I end up with this error:

'import sitecustomize' failed; use -v for traceback
Python 2.7.10+ (default, Oct 10 2015, 09:11:24)
[GCC 5.2.1 20151003] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/spyderlib/scientific_startup.py", line 36, in
from pylab import * #analysis:ignore
File "/usr/lib/python2.7/dist-packages/pylab.py", line 1, in
from matplotlib.pylab import *
File "/usr/lib/python2.7/dist-packages/matplotlib/pylab.py", line 231, in
import matplotlib.finance
File "/usr/lib/python2.7/dist-packages/matplotlib/finance.py", line 25, in
from matplotlib.dates import date2num
File "/usr/lib/python2.7/dist-packages/matplotlib/dates.py", line 136, in
import matplotlib.cbook as cbook
AttributeError: 'module' object has no attribute 'cbook'

Duplicate

Most helpful comment

I got the same error when I was using Jupyter notebook and trying to import matplotlib.
I don't know why but every time I got a weird error in the notebook, I shut it down and change the locale variable and start it again. This always help including this time.
Try to shut it down and type this in your terminal:
export LANG=en_US.UTF-8;export LC_ALL=en_US.UTF-8

All 8 comments

I get the same error on the starting up of spyder:

'import sitecustomize' failed; use -v for traceback
Python 2.7.10+ (default, Oct 10 2015, 09:11:24)
[GCC 5.2.1 20151003] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/spyderlib/scientific_startup.py", line 36, in
from pylab import * #analysis:ignore
File "/usr/lib/python2.7/dist-packages/pylab.py", line 1, in
from matplotlib.pylab import *
File "/usr/lib/python2.7/dist-packages/matplotlib/pylab.py", line 231, in
import matplotlib.finance
File "/usr/lib/python2.7/dist-packages/matplotlib/finance.py", line 25, in
from matplotlib.dates import date2num
File "/usr/lib/python2.7/dist-packages/matplotlib/dates.py", line 136, in
import matplotlib.cbook as cbook
AttributeError: 'module' object has no attribute 'cbook'

The error arose one week ago, after the last matplotlib update. I'm using Debian Stretch (Testing) and, according to Spyder, my current matplotlib version is 1.5 Orc2.
If this is also your case, I suppose that performing a downgrade of the package everything would work again...
Anyway, we can wait until Spyder's experts have a look at the problem.

I hope this can help...

I see the same behaviour that @juanjimenez describes (on Debian unstable). I can confirm that downgrading mitigates the problem. Interestingly, this error does not occur when using Spyder3.

Running PYTHONVERBOSE=1 spyder gives in the python console the following traceback:

import encodings.utf_8 # precompiled from /usr/lib/python2.7/encodings/utf_8.pyc
Traceback (most recent call last):
  File "/usr/lib/python2.7/site.py", line 513, in execsitecustomize
    import sitecustomize
  File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 218, in <module>
    import matplotlib
  File "/usr/lib/python2.7/dist-packages/matplotlib/__init__.py", line 1132, in <module>
    rcParams = rc_params()
  File "/usr/lib/python2.7/dist-packages/matplotlib/__init__.py", line 977, in rc_params
    return rc_params_from_file(fname, fail_on_error)
  File "/usr/lib/python2.7/dist-packages/matplotlib/__init__.py", line 1115, in rc_params_from_file
    config['datapath'] = get_data_path()
  File "/usr/lib/python2.7/dist-packages/matplotlib/__init__.py", line 320, in wrapper
    ret = func(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/matplotlib/__init__.py", line 720, in _get_data_path_cached
    defaultParams['datapath'][0] = _get_data_path()
  File "/usr/lib/python2.7/dist-packages/matplotlib/__init__.py", line 683, in _get_data_path
    _file = _decode_filesystem_path(__file__)
  File "/usr/lib/python2.7/dist-packages/matplotlib/__init__.py", line 668, in _decode_filesystem_path
    return path.decode(sys.getfilesystemencoding())
  TypeError: decode() argument 1 must be string, not None
  Python 2.7.10+ (default, Oct 10 2015, 09:11:24) 
  [GCC 5.2.1 20151003] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

But calling sys.getfilesystemencoding() in the interpreter produces the expected result:

 >>> import sys 
 >>> sys.getfilesystemencoding()

 'UTF-8'

Hope this helps a litte bit, Dietrich

PS: Versions used:
_Spyder_: Spyder 2.3.6 Python 2.7.10+ 64bits, Qt 4.8.7, PyQt4 (API v2) 4.11.4 on Linux
_Spyder3_: Spyder 2.3.6 Python 3.4.3+ 64bits, Qt 4.8.7, PyQt4 (API v2) 4.11.4 on Linux

Thanks @vollbier for the info. I'll try to solve this problem before 1.5.0 final is released.

I have also encountered this now I have upgraded to 1.5.0 final. Any news on a fix?

Working on it :-)

This is a duplicate of issue #2793.

I got the same error when I was using Jupyter notebook and trying to import matplotlib.
I don't know why but every time I got a weird error in the notebook, I shut it down and change the locale variable and start it again. This always help including this time.
Try to shut it down and type this in your terminal:
export LANG=en_US.UTF-8;export LC_ALL=en_US.UTF-8

I also met the same problem when I use spyder3. The problem is caused by the mess of env.
What I do is to do re-install the spyder3.

Was this page helpful?
0 / 5 - 0 ratings