Matplotlib ValueError: _getfullpathname: embedded null character

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 29, in <module>
    import matplotlib.colorbar
  File "C:\Anaconda3\lib\site-packages\matplotlib\colorbar.py", line 34, in <module>
    import matplotlib.collections as collections
  File "C:\Anaconda3\lib\site-packages\matplotlib\collections.py", line 27, in <module>
    import matplotlib.backend_bases as backend_bases
  File "C:\Anaconda3\lib\site-packages\matplotlib\backend_bases.py", line 62, in <module>
    import matplotlib.textpath as textpath
  File "C:\Anaconda3\lib\site-packages\matplotlib\textpath.py", line 15, in <module>
    import matplotlib.font_manager as font_manager
  File "C:\Anaconda3\lib\site-packages\matplotlib\font_manager.py", line 1420, in <module>
    _rebuild()
  File "C:\Anaconda3\lib\site-packages\matplotlib\font_manager.py", line 1405, in _rebuild
    fontManager = FontManager()
  File "C:\Anaconda3\lib\site-packages\matplotlib\font_manager.py", line 1043, in __init__
    self.ttffiles = findSystemFonts(paths) + findSystemFonts()
  File "C:\Anaconda3\lib\site-packages\matplotlib\font_manager.py", line 312, in findSystemFonts
    for f in win32InstalledFonts(fontdir):
  File "C:\Anaconda3\lib\site-packages\matplotlib\font_manager.py", line 231, in win32InstalledFonts
    direc = os.path.abspath(direc).lower()
  File "C:\Anaconda3\lib\ntpath.py", line 535, in abspath
    path = _getfullpathname(path)
ValueError: _getfullpathname: embedded null character

这个问题貌似是python不能正确读取字符串

解决办法是打开C:\Anaconda3\lib\site-packages\matplotlib\font_manager.py文件,查找winreg.EnumValue,你会看到这样的代码

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 = os.path.abspath(direc).lower()

将其替换成


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]

这样就可以画图了

Reference:http://stackoverflow.com/questions/34004063/error-on-import-matplotlib-pyplot-on-anaconda3-for-windows-10-home-64-bit-pc/34007642#34007642

posted on 2017-04-01 02:52  kinsly  阅读(1700)  评论(0编辑  收藏  举报

导航