Skip to content

font_manager.py UnicodeDecodeError when starting ipython --pylab - #2307

Merged
mdboom merged 2 commits into
matplotlib:v1.3.xfrom
mdboom:font-name-decoding
Aug 27, 2013
Merged

mdboom merged 2 commits into
matplotlib:v1.3.xfrom
mdboom:font-name-decoding

Conversation

@mdboom

@mdboom mdboom commented Aug 26, 2013

Copy link
Copy Markdown
Member

I'm experiencing a UnicodeDecodeError when starting ipython --pylab.
System: Debian Sid
$apt-cache policy python-matplotlib
python-matplotlib:
Installed: 1.3.0-1

This seems to be caused by on of the font name containing non-ascii characters. The font causing the issues seems to be " Systematic TT BRK" from the ttf-aenigma package in debian sid. Error message below:

/usr/lib/pymodules/python2.7/matplotlib/font_manager.py in ttfFontProperty(font)
396 sfnt2 = ''
397 if sfnt4:
--> 398 sfnt4 = sfnt4.decode('ascii').lower()
399 else:
400 sfnt4 = ''

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc6 in position 0: ordinal
not in range(128)

@cycomanic

Copy link
Copy Markdown
Author

Seems this can be fixed by changing line 398 from
sfnt4 = sfnt4.decode('ascii').lower()
to
sfnt4 = sfnt4.decode('ascii', 'ignore').lower()

however I'm not sure if this results in any side effects.

@ghost ghost assigned mdboom Aug 26, 2013
@mdboom

mdboom commented Aug 26, 2013

Copy link
Copy Markdown
Member

@cycomanic: Can you confirm this patch resolves your issue?

This may also fix #2320.

@mdboom

mdboom commented Aug 26, 2013

Copy link
Copy Markdown
Member

Thanks -- it was helpful to know the problematic font. It contains a non-ascii character as its name -- according to this (http://www.freetype.org/freetype2/docs/reference/ft2-truetype_tables.html#TT_MAC_ID_XXX), that entry is supposed to be "macroman" and not "ascii", so I've updated matplotlib to reflect that.

@cycomanic

Copy link
Copy Markdown
Author

I will try later tonight.

Cheers
Jochen

On 27/08/13 04:26, Michael Droettboom wrote:

@cycomanic: Can you confirm this patch resolves your issue?

This may also fix #2320.


Reply to this email directly or view it on GitHub:
#2307 (comment)

@megies

megies commented Aug 27, 2013

Copy link
Copy Markdown
Contributor

👍 Tried it, works! (See #2320 (comment))

mdboom added a commit that referenced this pull request Aug 27, 2013
font_manager.py UnicodeDecodeError when starting ipython --pylab
@mdboom
mdboom merged commit ffb3746 into matplotlib:v1.3.x Aug 27, 2013
@mjanikas

Copy link
Copy Markdown

I am having the same issue where my software package employs matplotlib1.3.0. We are almost about to release and I was hoping that you could confirm that in fact, the ONLY change needed to fix this issue is the movement of 'ascii' to 'macroman' in those two locations in font_manager.py.

BTW, we have a ton of harness tests across a myriad of languages and this solution had worked for us in regards to fixing the traceback. I am just being extra cautious. Thanks for the heads up ahead of time.
Cheers,

MJ

@mdboom
mdboom deleted the font-name-decoding branch August 7, 2014 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants