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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM