Matplotlib错误(ValueError:_getfullpathname:嵌入的空字符)

时间:2017-02-19 12:23:43

标签: python windows matplotlib

首先,我应该提一下,我根据' Error on import matplotlib.pyplot (on Anaconda3 for Windows 10 Home 64-bit PC)'修补了matplotlib的fontmanager.py. 我正在使用Windows 10和python3.5.2,并且只是在ipython笔记本中使用matplotlib运行超级简单的绘图。代码如下所示。

import numpy as np
import matplotlib.pyplot as plt

num_points = 1000
vectors_set = []
for i in range(num_points):
    x1 = np.random.normal(0.0, 0.55)
    y1 = x1*0.1 + 0.3 + np.random.normal(0.0, 0.03)
    vectors_set.append([x1, y1])

x_data =[v[0] for v in vectors_set]
y_data =[v[1] for v in vectors_set]

plt.plot(x_data, y_data)
plt.show()

但我仍然得到同样的错误。这是我的错误消息。

c:\python35\lib\site-packages\matplotlib\font_manager.py in findSystemFonts(fontpaths, fontext)
    323             fontpaths = [fontdir]
    324             # now get all installed fonts directly...
--> 325             for f in win32InstalledFonts(fontdir):
    326                 base, ext = os.path.splitext(f)
    327                 if len(ext)>1 and ext[1:].lower() in fontexts:

c:\python35\lib\site-packages\matplotlib\font_manager.py in win32InstalledFonts(directory, fontext)
    239                     if not os.path.dirname(direc):
    240                         direc = os.path.join(directory, direc)
--> 241                     direc = direc.split('\0', 1)[0]
    242                     if os.path.splitext(direc)[1][1:] in fontext:
    243                         items[direc] = 1

c:\python35\lib\ntpath.py in abspath(path)
    533         if path: # Empty path must return current working directory.
    534             try:
--> 535                 path = _getfullpathname(path)
    536             except OSError:
    537                 pass # Bad path - return unchanged.

ValueError: _getfullpathname: embedded null character

在第241行,它说:

direc = direc.split('\0', 1)[0]

像@simonzack建议的那样。

0 个答案:

没有答案