sagemath / sage-windows

Build tools for the Sagemath Windows installer
348 stars 47 forks source link

matplotlib font cache #42

Closed videlec closed 4 years ago

videlec commented 4 years ago

As reported in the sagemath 9 + Graph thread on sage-support, matlotlib seems to hang when generating its cache for fonts.

This happened on Windows 8.1 with SageMath-9.0-Installer-v0.5.2.

rickroesler commented 4 years ago

I have the same issue SageMath-9.0-Installer-v0.5.2 on Windows 10

Uninstalled/reinstalled. No effect. Still not working.

Uninstalled 9.0 and installed 8.9. Works.

embray commented 4 years ago

I don't know exactly how the matplotlib font cache works, but it's likely it involves Python pickles somehow, and is broken due to trying to load some Python 2 pickles on Python 3. Although that shouldn't be such a problem, I think I have seen cases (e.g. due to a bug in the pickle interpreter?) where this can hang, though I can't seem to quickly find a reference to a specific issue.

Try running rm -rf ~/.sage/matplotlib* in the SageMath Shell and it should be alright.

zfscgy commented 4 years ago

Ver9.0 Same problem, and cannot find ~/.sage/matplotlib folder. Ver8.9 is ok

rickroesler commented 4 years ago

Ver9.0 Same problem, and cannot find ~/.sage/matplotlib folder. Ver8.9 is ok

On my Windows 10 machine, I'm using all the install defaults. It's installing the program into /users/rickr/appdata/local

More importantly, the matplotlib font cache is located in (for v8.9; for v9.0 it creates this same directory, but it's empty).

/users/rickr/.sage/matplotlib-1.5.1

To follow the @embray solution, it's important not to drop the 'star' in "matplotlib*"

rickroesler commented 4 years ago

I don't know exactly how the matplotlib font cache works, but it's likely it involves Python pickles somehow, and is broken due to trying to load some Python 2 pickles on Python 3. Although that shouldn't be such a problem, I think I have seen cases (e.g. due to a bug in the pickle interpreter?) where this can hang, though I can't seem to quickly find a reference to a specific issue.

Try running rm -rf ~/.sage/matplotlib* in the SageMath Shell and it should be alright.

@embray this did not work for me

here are some things I tried:

  1. installed SageMath 9.0 with defaults; since 8.9 and 9.0 were using the same .sage directory structure, and since 8.9 created (and successfully used) the font cache, I hoped that 9.0 would just find what it needed and be happy; did not work
  2. moved the .sage/matplotlib-1.5.1 directory off to another place (so I wouldn't lose the 8.9 data); ran Sage 9.0; it recreated the matplotlib-1.5.1 directory, but still has the same error
  3. used your rm solution; still same error

(#2 and #3 should be the same; they both remove the existing folder)

embray commented 4 years ago

but still has the same error

Is there actually an error message, or just that it hangs?

rickroesler commented 4 years ago

but still has the same error

Is there actually an error message, or just that it hangs?

It hangs with this message: Matplotlib is building the font cache using fc-list. This may take a moment.

embray commented 4 years ago

Could somebody who's reported this problem open the SageMath Shell and produce the output of the following shell commands:

$ which fc-list
$ fc-list --format='%{file}\n' | wc -l
$ fc-list --format='%{file}\n'

If you think you know what you're doing, go to the path of the fc-list command and rename it to something like fc-list.bak and see if the problem still occurs.

rickroesler commented 4 years ago

SageMath shell fc-list log.txt

@embray Attached is the output of the shell commands

i renamed fc-list.exe to fc-list.bak and that DID fix the issue

btw, i don't know if it was ever explicity stated elsewhere, but to reproduce the issue:

  1. launch SageMath 9.0 console
  2. execute the command 'plot(sin(x))'
embray commented 4 years ago

btw, i don't know if it was ever explicity stated elsewhere, but to reproduce the issue:

Several people have suggested this but I can't reproduce it.

i renamed fc-list.exe to fc-list.bak and that DID fix the issue

If this works then it seems to be a problem somehow external to Sage, involving peoples' latex distributions. However, it's not obvious why the problem would have only occurred after upgrading to Sage 9.0 since I don't think there has even been a significant change in the matplotlib version (other than being Python 3 now by default instead of Python 2)

embray commented 4 years ago

@rickroesler Thanks for the debugging log. I see you have a texlive for Windows distribution installed. That shouldn't be a problem, of course, but it does give me a clue. I'll see if I can install it and see if that helps reproduce. I wonder if it's what other people who've reported this problem has, so it would be great if others could provide this output as well.

Was this installed using the distribution from https://www.tug.org/texlive/ ?

embray commented 4 years ago

@rickroesler Thanks to you I was able to reproduce the problem. Indeed, the fc-list program provided with texlive seems to cause the hang. I don't know why yet, but installing texlive and ensuring it was on my $PATH reproduced the problem. Previously I was using a miktex which also included fc-list, but it doesn't have this problem.

For some reason the Python 3 subprocess module is hanging when calling the fc-list included in texlive. Could be a bug in one or the other.

embray commented 4 years ago

Correction: The problem occurs on Python 2 as well. It's possible that when upgrading Sage, if they previously had an older version of Sage with an older matplotlib, that the font cache just happened to have to be rebuilt, triggering the problem. In principle the problem could have occurred on some older versions of Sage as well, but for some reason it just never came up then, so I'm a bit mystified. Maybe the problem is more specific to newer versions of texlive?

rickroesler commented 4 years ago

Was this installed using the distribution from https://www.tug.org/texlive/ ?

Yes.

embray commented 4 years ago

Turns out the bug was not in texlive nor in Python, but in Cygwin. I believe it's the same problem that's reported here, though I admit I don't fully understand the diagnosis (there has been a lot of rewriting going on in Cygwin's PTY and FIFO handling code of late): https://www.cygwin.com/ml/cygwin/2019-12/msg00173.html

I can confirm that the latest Cygwin nightly has the issue fixed.

I'll work on a new build using the previous Cygwin version.

rickroesler commented 4 years ago

@embray Thank you for tracking this down. Let me know if there's anything else I can do to help.

embray commented 4 years ago

This should be fixed now in the new release: https://github.com/sagemath/sage-windows/releases/tag/0.5.2-9.0

rickroesler commented 4 years ago

@embray Confirmed the new release does not have the issue. Thank you for fixing.

embray commented 4 years ago

Awesome, thank you so much for testing so quickly and confirming.

On Thu, Feb 13, 2020, 21:49 Rick Roesler notifications@github.com wrote:

@embray https://github.com/embray Confirmed the new release does not have the issue. Thank you for fixing.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sagemath/sage-windows/issues/42?email_source=notifications&email_token=AAFFCNOIVK7PMGOUVJ2HVQ3RCWW5ZA5CNFSM4KLRUWO2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELWR2RQ#issuecomment-585964870, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFFCNMLYPLTNTOEBXYU4C3RCWW5ZANCNFSM4KLRUWOQ .