-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Cannot import pyplot #12173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Same on a mac installed with conda if (mat_bug_py37) moonbase:~ lloyd$ ls -al /Users/lloyd/.matplotlib/fontlist-v300.json
-rw-r--r-- 1 lloyd staff 130027 Sep 19 10:45 /Users/lloyd/.matplotlib/fontlist-v300.json
(mat_bug_py37) moonbase:~ lloyd$ python -c 'from matplotlib import pyplot'
(mat_bug_py37) moonbase:~ lloyd$ rm /Users/lloyd/.matplotlib/fontlist-v300.json
(mat_bug_py37) moonbase:~ lloyd$ python -c 'from matplotlib import pyplot' hangs.... ctl-c ^CTraceback (most recent call last):
File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/font_manager.py", line 1353, in <module>
fontManager = json_load(_fmcache)
File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/font_manager.py", line 888, in json_load
with open(filename, 'r') as fh:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/lloyd/.matplotlib/fontlist-v300.json'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/pyplot.py", line 32, in <module>
import matplotlib.colorbar
File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/colorbar.py", line 32, in <module>
import matplotlib.contour as contour
File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/contour.py", line 18, in <module>
import matplotlib.font_manager as font_manager
File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/font_manager.py", line 1363, in <module>
_rebuild()
File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/font_manager.py", line 1344, in _rebuild
fontManager = FontManager()
File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/font_manager.py", line 978, in __init__
ttffiles = findSystemFonts(paths) + findSystemFonts()
File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/font_manager.py", line 270, in findSystemFonts
fontfiles.update(OSXInstalledFonts(fontext=fontext))
File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/font_manager.py", line 218, in OSXInstalledFonts
for directory in directories
File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/font_manager.py", line 220, in <listcomp>
for path in list_fonts(directory, ext)]
File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/font_manager.py", line 157, in list_fonts
for path in filter(Path.is_file, Path(directory).glob("**/*.*"))
File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/site-packages/matplotlib/font_manager.py", line 156, in <listcomp>
return [str(path)
File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/pathlib.py", line 1344, in is_file
return S_ISREG(self.stat().st_mode)
File "/Users/lloyd/anaconda2/envs/mat_bug_py37/lib/python3.7/pathlib.py", line 1140, in stat
return self._accessor.stat(self)
KeyboardInterrupt
^C
|
I have the same issue, the same error. matplotlib 3.00. Doesn't find fontlist-v300.json |
Not finding that file in fine, it is a cache and automatically re-generated. |
from matplotlib.font_manager import win32InstalledFonts
print(win32InstalledFonts()) Output:
Added logging to import winreg
from matplotlib.font_manager import MSFontDirectories, win32FontDirectory
from pathlib import Path
fontext = 'ttf'
directory = win32FontDirectory()
items = set()
for fontdir in MSFontDirectories:
try:
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, fontdir) as local:
for j in range(winreg.QueryInfoKey(local)[1]):
key, direc, tp = winreg.EnumValue(local, j)
if not isinstance(direc, str):
print('Skipped "{}" because is of type: {}'.format(direc, type(direc)))
continue
# Work around for https://bugs.python.org/issue25778, which
# is fixed in Py>=3.6.1.
direc = direc.split("\0", 1)[0]
path = Path(directory, direc).resolve()
if path.suffix.lower() in fontext:
items.add(str(path))
else:
print('Skipped "{}" because font format "{}" is not supported'.format(path, path.suffix.lower()))
print('Return font list: {}'.format(list(items)))
break
except (OSError, MemoryError) as e:
print('Skipped "{}" because of error: {}'.format(fontdir, e))
continue Output:
So we have a problem... |
There are more problem usages of
|
The problem is that `Path(...).suffix` includes the dot, so ``.ttf` in 'ttf'` gives `False`. Also fixed other suffix usages. Fixes #12173
Thanks for investigating. |
Oops, that's something I had misconception, I thought |
For lists too you can pass an "invalid" slice and it'll just give you an empty list. |
#12212 will not solve the issue. The |
I think #12174 is just fine to handle this case. Perhaps we were just lucky not to have run into that before? |
I don't think we should overly bother about cases where well-documented regsitry keys are missing (i.e. I don't think we should try too hard to find the fonts in that case). |
I am not sure what is the purpose of matplotlib/lib/matplotlib/font_manager.py Line 275 in 333dad1
win32FontDirectory()
Is not |
Well, at least technically win32InstalledFonts can return fonts that are not in win32FontDirectory(), as the registry can specify absolute paths (https://superuser.com/a/1258913/41302). |
Well, then I am taking back my last message... So, may be than solve the both problems (#12174 (comment) and #12173/#12213) by replacing matplotlib/lib/matplotlib/font_manager.py Line 209 in 333dad1
return list(items) ?
|
That'll be [] in any case, no? |
No, for example if |
Then just change to call EnumValue until it raises OSError, as officially documented? (https://docs.python.org/3/library/winreg.html#winreg.EnumValue) |
I think changing matplotlib/lib/matplotlib/font_manager.py Line 206 in 333dad1
|
That seems actually the best solution. Thanks for spotting the details. |
Closed in #12213 |
Unfortunately, no. |
Hi, I just downloaded and am still getting the same error:
Any other ideas? |
@sebastianjungels what did you put in the missing file? |
Hi, I got the file from a colleague who didn't face the problem.
Let me know if you need it.
Thanks,
Sebastian
…________________________________
From: Thomas A Caswell <notifications@github.com>
Sent: Friday, October 5, 2018 4:23:05 PM
To: matplotlib/matplotlib
Cc: Sebastian Jungels; Mention
Subject: Re: [matplotlib/matplotlib] Cannot import pyplot (#12173)
@sebastianjungels<https://github.com/sebastianjungels> what did you put in the missing file?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#12173 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ApAv0T5MPBaEsgV6Sgad7Zs2Acp4ePqMks5uh825gaJpZM4WwVec>.
|
I would not have thought to try that.... Given that the cache encodes some local paths I am a bit surprised that this works.... |
@sebastianjungels Can you please install a snapshot build from #12416 (wheels 3.5 3.6 3.7) and provide us a traceback of the error? |
@Kojoley sure, I can do that. However, I am fairly new to git and am not sure how I can install that build. can you point me to a link or provide the steps? Cheers |
I have included links to wheels in my last post. You should be able to install one with |
Just experienced this issue in a conda environment with I guess this is the best workaround until this fix is released? |
@drdavella The OP here is a windows-specific bug (issues with getting keys out of the the windows registry) so I suspect you were seeing a different issue. I am very confused by the report that changing what directory you are in making a difference, but if it does, that is almost certainly a bug we need to fix! Can you open a new issue with more detials (if you can still reproduce the issue). |
@tacaswell, oops I guess I skimmed this a little too quickly! Yes I can still reproduce it, so I'll open a new issue presently. UPDATE: See #12556 |
Just wanted to add that as of today I can still reproduce it. Using Windows 10 with a 32-bit version of Python 3.5.2, installed mathplotlib via pip, and I get the exact same error when importing the module. |
@deansg That is expected, the fix is in the source but has not been released yet. The current plan is to release 3.0.1 around Nov 3. |
@tacaswell Alright, I wasn't sure about it because after reading the entire exchange, at one point the focus shifted to a (possibly different?) bug in OSX and I couldn't figure out what the current status is. Maybe it will be beneficial to include an explicit workaround in the description (such as downgrading to 2.2.3)? |
What is the solution for this? |
@erotavlas you should be able to install 3.0.1 using conda now. |
@drdavella it wont let me, either from the prompt (conda update matplotlib) or from the anaconda navigator...it says "All requested packaged already installed " |
Just installed v3.0.2 and am getting the exact same error. Python 3.6.0. Windows 8.1. |
Are you all getting v3.0.1 now? My conda still only has v3.0.0 (python 3.6.8). Actually v3.0.0 has been working fine for me, until I did the following update recently, then I started to get this error: The following packages will be UPDATED:
Update: I installed v.3.0.2 from conda-forge channel and the issue is fixed. |
Unfortunately, I have encountered the same issue just now. I needed seaborn because it seemed not be installed (oddly), so I ran Next, I receive a warning that a newer conda version exists 4.5.12 while I was running 4.511. So I follow instructions to update that. It all proceeds to downloading a number of packages including seaborn-0.9.0 and matplotlib-3.0.0 All funky, apparently, until I run import matplotlib and I get the error: I'm now stuck without a functioning matplotlib. To fix this problem, I try this: Same problem and worse because it wants to now downgrade a ton of packages. I rejected this install. What do I do now? |
This issue is still reproduced for me on gentoo linux for python 3.6.10 + matplotlib 3.1.2 with error about no such file in "/home/user/.cache/matplotlib/fontlist-v310.json" |
Bug report
Bug summary
I am unable to
import matplotlib.pyplot
starting in version 3.0.0. Might be related to Issue #9485?Code for reproduction
Actual outcome
I get the following traceback when executing the above
import
Matplotlib version
Installed via
pip
The text was updated successfully, but these errors were encountered: