[python] matplotlib를 가져올 때 시간이 걸립니다.

방금 matplotlib(1.5.1) 의 최신 안정 릴리스로 업그레이드했으며 matplotlib를 가져올 때마다 다음 메시지가 표시됩니다.

/usr/local/lib/python2.7/dist-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.')

… 항상 몇 초 동안 멈 춥니 다.

이것이 예상되는 동작입니까? 이전에도 동일했지만 인쇄 된 메시지가 없었습니까?



답변

위의 주석에서 제안한대로 파일을 삭제합니다.

fontList.cache
fontList.py3k.cache
tex.cache 

문제를 풀다. 제 경우 파일은 다음과 같습니다.

`~/.matplotlib`

편집 됨

며칠 전에 메시지가 다시 나타 났고 위에서 언급 한 위치의 파일을 성공적으로 삭제했습니다. 내가 제안 발견 여기 에서 T Mudau 텍스트 캐시 파일이 추가 위치는있다 :~/.cache/fontconfig


답변

Hugo의 접근 방식이 Ubuntu 14.04 LTS / matplotlib 1.5.1에서 작동하는지 확인했습니다.

  • ~ / .cache / matplotlib / fontList.cache 삭제
  • 코드 실행, 다시 경고가 발행되었습니다 (가정 : 캐시를 올바르게 재 구축하고 있음).
  • 다시 코드 실행, 더 이상 경고 없음 (마지막으로)

답변

OSX Yosemite (버전 10.10.15)에서 다음이 저에게 효과적이었습니다.

  • 이 디렉토리에서도 캐시 파일을 제거하십시오 : ~ / .cache / fontconfig (톰의 제안에 따라)
    rm -rvf ~/.cache/fontconfig/*
  • ~ / .matplotlib에서 .cache 파일도 제거했습니다 (Hugo의 제안에 따라).
    rm -rvf ~/.matplotlib/*

답변

sudo를 사용하여 파이썬 코드를 한 번만 실행했는데 경고가 해결되었습니다. 이제 더 빠르게 실행됩니다. sudo없이 실행하면 경고가 전혀 발생하지 않습니다.

건배


답변

나는 파이썬 코드 w를 실행했습니다. sudo와 그것은 그것을 치료했습니다 … 내 추측은 그 테이블을 쓸 수있는 권한이 없다는 것입니다 … 행운을 빕니다!


답변

안녕 당신은이 파일을 찾아야합니다 : 내 경우에는 font_manager.py : C : \ Users \ gustavo \ Anaconda3 \ Lib \ site-packages \ matplotlib \ font_manager.py

def win32InstalledFonts (directory = None, fontext = ‘ttf’)를 찾아 다음으로 대체하십시오.

def win32InstalledFonts (directory = None, fontext = ‘ttf’) : “” “지정된 글꼴 디렉토리에서 글꼴을 검색하거나 지정되지 않은 경우 시스템 디렉토리를 사용합니다. 기본적으로 TrueType 글꼴 파일 이름 목록이 반환되고 다음의 경우 AFM 글꼴이 반환됩니다. fontext == ‘afm’. “” “

from six.moves import winreg
if directory is None:
    directory = win32FontDirectory()

fontext = get_fontext_synonyms(fontext)

key, items = None, {}
for fontdir in MSFontDirectories:
    try:
        local = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, fontdir)
    except OSError:
        continue

    if not local:
        return list_fonts(directory, fontext)
    try:
        for j in range(winreg.QueryInfoKey(local)[1]):
            try:
                key, direc, any = winreg.EnumValue(local, j)
                if not is_string_like(direc):
                    continue
                if not os.path.dirname(direc):
                    direc = os.path.join(directory, direc)
                    direc = direc.split('\0', 1)[0]

                if os.path.splitext(direc)[1][1:] in fontext:
                    items[direc] = 1
            except EnvironmentError:
                continue
            except WindowsError:
                continue
            except MemoryError:
                continue
        return list(six.iterkeys(items))
    finally:
        winreg.CloseKey(local)
return None


답변

이것은 Python 3.5.2를 사용 하는 Ubuntu 16.04 LST 에서 저에게 효과적 이었습니다. Anaconda 4.2.0 (64 비트) . .NET의 모든 파일을 삭제했습니다 ~/.cache/matplotlib/.

sudo rm -r fontList.py3k.cache tex.cache 

나중에 경고를 받았기 때문에 처음에는 작동하지 않을 것이라고 생각했습니다. 그러나 캐시 파일이 재 구축 된 후 경고가 사라졌습니다. 따라서 파일을 닫고 다시 열면 (다시 열기) 경고가 없습니다.