Bug 18457 - matplotlib for python3 misses fonts
Summary: matplotlib for python3 misses fonts
Status: RESOLVED FIXED
Alias: None
Product: Mageia
Classification: Unclassified
Component: RPM Packages (show other bugs)
Version: 5
Hardware: All Linux
Priority: Normal major
Target Milestone: ---
Assignee: QA Team
QA Contact:
URL:
Whiteboard: has_procedure MGA5-64-OK MGA5-32-OK a...
Keywords: validated_update
Depends on:
Blocks:
 
Reported: 2016-05-14 11:52 CEST by funny name
Modified: 2016-06-11 18:02 CEST (History)
5 users (show)

See Also:
Source RPM: python-matplotlib
CVE:
Status comment:


Attachments
The code to reproduce the error. (81 bytes, text/x-python)
2016-05-14 11:54 CEST, funny name
Details
Installation and error logs (12.05 KB, text/plain)
2016-05-19 23:30 CEST, Len Lawrence
Details
test ok under Mageia 5 LXDE x86_64 (16.19 KB, text/plain)
2016-05-20 13:52 CEST, Philippe Makowski
Details

Description funny name 2016-05-14 11:52:13 CEST
Description of problem:
Latex code for matplotlib plots doesn't work with python3. There are UserWarnings and the code is not rendered correctly. This means you cannot print mathematical formulae on plots when you use python3 instead of python


How reproducible:
Always when running a script containing latex code in matplotlib functions.

Steps to Reproduce:
1. Generate a file matplotlib_POC.py with the following content:
import matplotlib.pyplot as plt

plt.clf()
plt.xlabel("$Latex Test$")

plt.show()

2. python3 matplotlib_POC.py
Comment 1 funny name 2016-05-14 11:54:08 CEST
Created attachment 7794 [details]
The code to reproduce the error.
Marja Van Waes 2016-05-14 20:11:55 CEST

CC: (none) => marja11
Assignee: bugsquad => makowski.mageia
Source RPM: (none) => python-matplotlib

Comment 2 Philippe Makowski 2016-05-17 15:13:50 CEST
Please test new packages in 5/core/testing

Suggested advisory:
========================
Fix missing fonts in python3-matplotlib package


Updated packages in core/updates_testing:
=========================================

python3-matplotlib-1.4.3-1.1.mga5
python3-matplotlib-qt4-1.4.3-1.1.mga5
python3-matplotlib-tk-1.4.3-1.1.mga5
python-matplotlib-1.4.3-1.1.mga5
python-matplotlib-cairo-1.4.3-1.1.mga5
python-matplotlib-data-1.4.3-1.1.mga5.noarch
python-matplotlib-data-fonts-1.4.3-1.1.mga5.noarch
python-matplotlib-doc-1.4.3-1.1.mga5.noarch
python-matplotlib-gtk-1.4.3-1.1.mga5
python-matplotlib-gtk3-1.4.3-1.1.mga5
python-matplotlib-pgf-1.4.3-1.1.mga5
python-matplotlib-qt4-1.4.3-1.1.mga5
python-matplotlib-qt5-1.4.3-1.1.mga5
python-matplotlib-qt-shared-1.4.3-1.1.mga5
python-matplotlib-svg-1.4.3-1.1.mga5
python-matplotlib-tk-1.4.3-1.1.mga5
python-matplotlib-wx-1.4.3-1.1.mga5

from python-matplotlib-1.4.3-1.1.mga5.src
Philippe Makowski 2016-05-17 15:15:01 CEST

Assignee: makowski.mageia => qa-bugs

Comment 3 Len Lawrence 2016-05-19 22:00:08 CEST
Testing this for x86_64

CC: (none) => tarazed25

Comment 4 Len Lawrence 2016-05-19 23:28:37 CEST
Not sure what to make of this.  Installed the pre-update packages (a big bundle) and ran the PoC test with python3 and it returned font errors and aborted without creating the fontlist cache.

After the update it also failed to create the cache because of errors.  All the errors appear to be font related.

Last few lines in both cases:

    name = font.get_familyname()
  File "/usr/lib64/python3.4/site-packages/matplotlib/afm.py", line 521, in get_familyname
    return re.sub(extras, '', name)
  File "/usr/lib64/python3.4/re.py", line 179, in sub
    return _compile(pattern, flags).sub(repl, string, count)
TypeError: can't use a bytes pattern on a string-like object

The logs for the two sessions can be found in the attached file.
Comment 5 Len Lawrence 2016-05-19 23:30:23 CEST
Created attachment 7813 [details]
Installation and error logs
Comment 6 Len Lawrence 2016-05-20 00:10:19 CEST
Just out of curiosity I tried the test under another user with a barebones home directory and saw similar errors with the difference that the cache defaulted to /tmp because there was no .local directory.  The cache was not created.

This was to rule out any peculiarities in my personal setup, where I have a .local/share/fonts directory.
Comment 7 Len Lawrence 2016-05-20 00:18:09 CEST
Running the test under python generates a similar final error message.

Found an unknown keyword in AFM header (was )
Found an unknown keyword in AFM header (was This)
Found an unknown keyword in AFM header (was )
Traceback (most recent call last):
  File "./poc.py", line 3, in <module>
    import matplotlib.pyplot as plt
  File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 27, in <module>
    import matplotlib.colorbar
  File "/usr/lib64/python2.7/site-packages/matplotlib/colorbar.py", line 34, in <module>
    import matplotlib.collections as collections
  File "/usr/lib64/python2.7/site-packages/matplotlib/collections.py", line 27, in <module>
    import matplotlib.backend_bases as backend_bases
  File "/usr/lib64/python2.7/site-packages/matplotlib/backend_bases.py", line 56, in <module>
    import matplotlib.textpath as textpath
  File "/usr/lib64/python2.7/site-packages/matplotlib/textpath.py", line 19, in <module>
    import matplotlib.font_manager as font_manager
  File "/usr/lib64/python2.7/site-packages/matplotlib/font_manager.py", line 1415, in <module>
    _rebuild()
  File "/usr/lib64/python2.7/site-packages/matplotlib/font_manager.py", line 1400, in _rebuild
    fontManager = FontManager()
  File "/usr/lib64/python2.7/site-packages/matplotlib/font_manager.py", line 1059, in __init__
    self.afmlist = createFontList(self.afmfiles, fontext='afm')
  File "/usr/lib64/python2.7/site-packages/matplotlib/font_manager.py", line 575, in createFontList
    prop = afmFontProperty(fpath, font)
  File "/usr/lib64/python2.7/site-packages/matplotlib/font_manager.py", line 491, in afmFontProperty
    if font.get_angle() != 0 or name.lower().find('italic') >= 0:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf3 in position 2: ordinal not in range(128)
Comment 8 Philippe Makowski 2016-05-20 13:52:54 CEST
Created attachment 7817 [details]
test ok under Mageia 5 LXDE x86_64

I don't understand why  Len Lawrence have such problems
here my full test log under a clean new up to date Mageia 5 LXDE x86_64 box

CC: (none) => makowski.mageia

Philippe Makowski 2016-05-20 13:56:44 CEST

Whiteboard: (none) => has_procedure mga5-64-ok

Comment 9 Len Lawrence 2016-05-20 18:04:50 CEST
Nor do I Philippe.  These things happen to me.  The system has been installed for several weeks, maybe months, and is up-to-date.
Comment 10 claire robinson 2016-05-20 18:13:45 CEST
Testing mga5 64

More or less find the same as Philippe. 

# urpmi python-matplotlib python-matplotlib-cairo python-matplotlib-doc python-matplotlib-gtk python-matplotlib-gtk3 python-matplotlib-pgf python-matplotlib-qt-shared python-matplotlib-qt4 python-matplotlib-qt5 python-matplotlib-svg python-matplotlib-tk python-matplotlib-wx python3-matplotlib python3-matplotlib-qt4 python3-matplotlib-tk


Before
------
Run under python it shows lots of these for copyright notices.
Value error parsing header in AFM: b'Notice' b'\xa9 2015 Microsoft Corporation. All Rights Reserved.'

Run under python3 it shows the expected errors but none of the above.

No tracebacks for either and the application opens OK.

After
-----
Run under python it shows no warnings at all.

Run under python 3 it now shows  lots of errors with copyright notices.
Value error parsing header in AFM: b'Notice' b'\xa9 2015 Microsoft Corporation. All Rights Reserved.'

Again no tracebacks for either and the application opens ok.


Not sure what to make of the issues Len is finding. I'll try in a fresh mga5 32 vbox install.
Comment 11 Len Lawrence 2016-05-20 18:33:39 CEST
[OT]
2:1 odds seem to imply that this system is corrupt in some way, which makes it unreliable for testing as a whole.  It is the main testing machine here but I have a laptop with a fresh mga5 install and may repeat the tests there.  If the main workstation cannot be trusted it will be difficult to believe the results of any subsequent tests.
Comment 12 claire robinson 2016-05-20 18:38:07 CEST
mga5 32

On a fresh installation it's exactly as Philippe's. It seems the previous errors come from fonts installed afterwards and it's unable to parse a copyright symbol in the font. Perhaps a similar issue causing Len's crashes.

Is this something of concern Philippe?
Comment 13 Philippe Makowski 2016-05-20 20:24:58 CEST
(In reply to claire robinson from comment #12)
> 
> On a fresh installation it's exactly as Philippe's. It seems the previous
> errors come from fonts installed afterwards and it's unable to parse a
> copyright symbol in the font. Perhaps a similar issue causing Len's crashes.
> 
it's seem yes, but these is another issue.
may be we need another bug report for that.
I would like to know what are the fonts that lead to this issue, a Microsoft one ? if I could install them, it would be helpful to to try to solve the issue.
after update is the initial bug report solved ?
if yes may be we can push the update, and work on the font issue in another bug, if the parse errors are not blocking.
Comment 14 claire robinson 2016-05-20 21:10:33 CEST
The error messages don't show the font name, so no way of knowing. 
There are many of them though, perhaps all ttf's?

It seems to have been cured in python-matplotlib and introduced in python3-matplotlib by this update. Unless it was there all along and being masked by the original issue.

WDYT?
Comment 15 Len Lawrence 2016-05-21 01:10:30 CEST
Will have a closer look at the logs and maybe try a process of elimination.  If the culprit(s) can be identified you might find the AFM file(s) of some use.

I would have installed them by converting an original TTF to AFM/PFB maybe by drakfont, maybe using ttf2pt1.  Have used both.
Comment 16 Philippe Makowski 2016-05-21 07:47:44 CEST
(In reply to claire robinson from comment #14)
> Unless it was there all along and being
> masked by the original issue.
> 
that's it
and I see upstream some changes in code related to such issues between 1.4.x and 1.5.x versions
may be I can build a 1.5 package in 5/backports to see if it's better on your boxes .
Comment 17 Philippe Makowski 2016-05-24 18:37:46 CEST
Please test new packages in 5/core/testing

Suggested advisory:
========================
Fix missing fonts in python3-matplotlib package


Updated packages in core/updates_testing:
=========================================

python3-matplotlib-1.4.3-1.2.mga5
python3-matplotlib-qt4-1.4.3-1.2.mga5
python3-matplotlib-tk-1.4.3-1.2.mga5
python-matplotlib-1.4.3-1.2.mga5
python-matplotlib-cairo-1.4.3-1.2.mga5
python-matplotlib-data-1.4.3-1.2.mga5.noarch
python-matplotlib-data-fonts-1.4.3-1.2.mga5.noarch
python-matplotlib-doc-1.4.3-1.2.mga5.noarch
python-matplotlib-gtk-1.4.3-1.2.mga5
python-matplotlib-gtk3-1.4.3-1.2.mga5
python-matplotlib-pgf-1.4.3-1.2.mga5
python-matplotlib-qt4-1.4.3-1.2.mga5
python-matplotlib-qt5-1.4.3-1.2.mga5
python-matplotlib-qt-shared-1.4.3-1.2.mga5
python-matplotlib-svg-1.4.3-1.2.mga5
python-matplotlib-tk-1.4.3-1.2.mga5
python-matplotlib-wx-1.4.3-1.2.mga5

from python-matplotlib-1.4.3-1.2.mga5.src
Comment 18 claire robinson 2016-06-02 23:22:47 CEST
Removing OK, fresh tests rqd.

Whiteboard: has_procedure mga5-64-ok => has_procedure

Comment 19 Len Lawrence 2016-06-03 16:16:06 CEST
Testing this again, on x86_64.

Installed all the updates and ran the PoC against python3.  No problems.
$ python3 poc.py
/usr/lib64/python3.4/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.')
/usr/lib64/python3.4/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.')

This generated a gui containing a blank plot called Figure1 with the x-axis labelled LatexTest.

python produced the same result.
Len Lawrence 2016-06-03 16:16:25 CEST

Whiteboard: has_procedure => has_procedure MGA5-64-OK

Comment 20 Len Lawrence 2016-06-03 16:52:17 CEST
i586 in virtualbox.

Ran the PoC before and after the update with the same results.
Validating this.
Len Lawrence 2016-06-03 16:52:47 CEST

Keywords: (none) => validated_update
Whiteboard: has_procedure MGA5-64-OK => has_procedure MGA5-64-OK MGA5-32-OK
CC: (none) => sysadmin-bugs

Dave Hodgins 2016-06-07 20:29:00 CEST

CC: (none) => davidwhodgins
Whiteboard: has_procedure MGA5-64-OK MGA5-32-OK => has_procedure MGA5-64-OK MGA5-32-OK advisory

Comment 21 Mageia Robot 2016-06-07 23:40:37 CEST
An update for this issue has been pushed to the Mageia Updates repository.

http://advisories.mageia.org/MGAA-2016-0087.html

Status: NEW => RESOLVED
Resolution: (none) => FIXED

Comment 22 funny name 2016-06-08 11:37:23 CEST
I've updated my production machine. When I run the PoC with python the first time after installing the updates, the following message appears:

/usr/lib64/python3.4/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.')

When I run it with python3, the above message appears twice. I'm not sure if this is desired or if it happens just because of the update. Anyways, the problem is solved. I've also run a "real-world script" from my studies, and all Latex code is rendered correctly.

Thank you very much for your work and commitment! The Mageia project shows once more that it has an amazing community!
Comment 23 Philippe Makowski 2016-06-11 18:02:51 CEST
the UserWarning is new in Matplotlib, it's from upstream, I backported the code from Matplotlib 1.5.1

Note You need to log in before you can comment on or make changes to this bug.