Skip to content

fail to import matplotlib.pyplot #2320

Closed

Description

@matthiasdresden

I have found the following problem:

I tried a new Installation of Python 3.3.2 64-bit with WinPython-64bit-3.3.2.2 on a Windows 7 64 bit machine.

Ever when I try to import matplotlib.pyplot (with some of my user accounts i use on this Windows-7 machine) I get tthe following error message:

Traceback (most recent call last):
File "D:\WinPython_3.3.2.2\python-3.3.2.amd64\lib\site-packages\matplotlib\font_manager.py", line 1348, in
fontManager = pickle_load(_fmcache)
File "D:\WinPython_3.3.2.2\python-3.3.2.amd64\lib\site-packages\matplotlib\font_manager.py", line 947, in pickle_load
with open(filename, 'rb') as fh:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\Jobst3.matplotlib\fontList.py3k.cache'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 1, in
File "D:\WinPython_3.3.2.2\python-3.3.2.amd64\lib\site-packages\matplotlib\pyplot.py", line 24, in
import matplotlib.colorbar
File "D:\WinPython_3.3.2.2\python-3.3.2.amd64\lib\site-packages\matplotlib\colorbar.py", line 29, in
import matplotlib.collections as collections
File "D:\WinPython_3.3.2.2\python-3.3.2.amd64\lib\site-packages\matplotlib\collections.py", line 23, in
import matplotlib.backend_bases as backend_bases
File "D:\WinPython_3.3.2.2\python-3.3.2.amd64\lib\site-packages\matplotlib\backend_bases.py", line 50, in
import matplotlib.textpath as textpath
File "D:\WinPython_3.3.2.2\python-3.3.2.amd64\lib\site-packages\matplotlib\textpath.py", line 11, in
import matplotlib.font_manager as font_manager
File "D:\WinPython_3.3.2.2\python-3.3.2.amd64\lib\site-packages\matplotlib\font_manager.py", line 1356, in
_rebuild()
File "D:\WinPython_3.3.2.2\python-3.3.2.amd64\lib\site-packages\matplotlib\font_manager.py", line 1341, in _rebuild
fontManager = FontManager()
File "D:\WinPython_3.3.2.2\python-3.3.2.amd64\lib\site-packages\matplotlib\font_manager.py", line 1004, in init
self.ttflist = createFontList(self.ttffiles)
File "D:\WinPython_3.3.2.2\python-3.3.2.amd64\lib\site-packages\matplotlib\font_manager.py", line 584, in createFontList
prop = ttfFontProperty(font)
File "D:\WinPython_3.3.2.2\python-3.3.2.amd64\lib\site-packages\matplotlib\font_manager.py", line 398, in ttfFontProperty
sfnt4 = sfnt4.decode('ascii').lower()
UnicodeDecodeError: 'ascii' codec can't decode byte 0x82 in position 0: ordinal not in range(128)

The same issue happens with other python version (3.2.3 64 bit, as I installed matplotlib 1.3. with easy install).

I found out that this happens only with newly created user accounts, but not with older accounts. As I found out, python is looking for a file located in the user folder: C:\Users\Jobst3.matplotlib\fontList.py3k.cache' which is not there in the newly created user account.

But the file is available in older user accounts. The file was created by an older version of matplotlib (matplotlib-1.2.0rc2.win-amd64-py3.2), and everything goes fine, if i use these accounts.

I am not able to test the issue on a complete new and clean Windows-7 machine at the moment

Matthias

Activity

  1. mdboom commented on Aug 21, 2013

    @mdboom
    Member

    It's having trouble reading the information from a particular font, probably because it doesn't contain the Macintosh SFNT tables (which was the defacto "standard" until recently when Microsoft started releasing fonts without them). The ongoing MEP14 should resolve these sorts of errors. Before that is done, it should probably be possible to get past this by decoding using utf16be for these particular fonts only. I'm on vacation this week -- just wanted to notate the problem in case anyone else is able to get to it first.

  2. WeatherGod commented on Aug 21, 2013

    @WeatherGod
    Member

    An interesting observation... the line numbers from those traceback statements lines up perfectly with the original source code in the git repository. Why is this strange, you ask? Because we still target py2.6 as we code, and py3k installs are supposed to go through 2to3 (or is it six now?), which invariably messes around a bit with adding new lines of code and such. Furthermore, the error has to do with unicode handling, which is what 2to3 typically tries to fix in most of our codebase.

  3. megies commented on Aug 24, 2013

    @megies
    Contributor

    I think I am running into the same problem (Python 2.7.5) after updating matplotlib to new version 1.3.0 (also, it seems to me this report comes from the same issue:http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=719065 ). The cause seems to be by a non-ascii character in a font name:

    ipdb> l 402
        397     if sfnt4:
        398         try:
        399             sfnt4 = sfnt4.decode('ascii').lower()
        400         except:
        401             from IPython.core.debugger import Tracer; Tracer(colors="Linux")()
        402     else:
        403         sfnt4 = ''
    --> 404     if sfnt4.find('oblique') >= 0:
        405         style = 'oblique'
        406     elif sfnt4.find('italic') >= 0:
        407         style = 'italic'
    
    ipdb> print sfnt4
    � Systematic TT BRK
    

    I noticed that the only change from v1.2.1 to master is the .decode('ascii') in there..:
    https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/font_manager.py#L394-L398
    https://github.com/matplotlib/matplotlib/blob/v1.2.1/lib/matplotlib/font_manager.py#L393-L397

  4. mdboom commented on Aug 26, 2013

    @mdboom
    Member

    @megies: Where is the IPython.core.debugger line coming from? That's not in matplotlib. Is that a Debian patch, or something you added yourself?

    From either @megies or @matthiasdresden: it would be helpful to know which font file is causing this failure. Can you put verbose.level: debug-annoying in your matplotlibrc? It will print out as it reads each font, and the last one before the traceback should be the culprit. Then I'll need a copy of that file to reproduce locally and find a solution. You can send that to me in a private e-mail at mdroe at stsci dot edu.

  5. mdboom commented on Aug 26, 2013

    @mdboom
    Member

    @megies, @matthiasdresden: Would you mind checking the patch in #2320 to see if it resolves your issue?

  6. megies commented on Aug 27, 2013

    @megies
    Contributor

    @megies: Where is the IPython.core.debugger line coming from? That's not in matplotlib. Is that a Debian patch, or something you added yourself?

    Sorry if that was confusing, I put it there myself to debug this (and that was the only change in the code).

    As for the font, I'll look it up tomorrow.

  7. megies commented on Aug 27, 2013

    @megies
    Contributor

    This is the font its struggling with (last line of debug output before the Exception):

    createFontDict: /usr/share/fonts/truetype/aenigma/aesymatt.ttf
    

    The font is directly available on the debian sources server:

    http://sources.debian.net/src/ttf-aenigma
    http://sources.debian.net/src/ttf-aenigma/0.0.20080510.dfsg-2/afonts/aesymatt.ttf
    

    The character causing this seems to be Æ (looks like Ænigma is the font designer's nickname).

  8. mdboom commented on Aug 27, 2013

    @mdboom
    Member

    Thanks. That's coincidentally the same font that was tripping someone up in #2307. Are you able to check out that PR to test?

  9. megies commented on Aug 27, 2013

    @megies
    Contributor

    Oh right, forgot about trying the PR..

    Tried it now and it works fine!

  10. mdboom commented on Aug 27, 2013

    @mdboom
    Member

    Closed by #2307.

  11. megies commented on Aug 27, 2013

    @megies
    Contributor

    Great. Thanks for the fix.

  12. liori commented on Aug 31, 2013

    @liori

    This patch results in botched font name for EPSON family fonts, available here: http://www.epson.jp/download2/printer/driver/win/page/ttf30.htm. I found that apparently their names are encoded in SHIFT-JIS instead of macroman (which is used in this patch), and apparently this happened often enough that even fontconfig has a heuristics to find out this case: http://cgit.freedesktop.org/fontconfig/tree/src/fcfreetype.c#n606.

    I personally don't care about using these fonts in matplotlib, but you might be interested in replicating fontconfig behavior for other users.

  13. mdboom commented on Sep 3, 2013

    @mdboom
    Member

    @liori: Wow. That's crappy. If the fonts are violating the spec, they're violating the spec. I don't know how far down the road I want to go of adding heuristics so support what are essentially broken fonts. We could do better at skipping over them, however. That's really what I think I'd prefer to do.

  14. reopened this on Sep 3, 2013
  15. mdboom commented on Sep 3, 2013

    @mdboom
    Member

    Closing. Already fixed in master.

  16. drcrook1 commented on Jan 15, 2018

    @drcrook1

    Just gonna put out there I ran into this just recently with conda 4.3.29 and python 3.6 on windows 10.

  17. tacaswell commented on Jan 15, 2018

    @tacaswell
    Member

    @drcrook1 please open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions