我不知道如何解决它请帮助,我已经尝试了帖子Error on import matplotlib.pyplot (on Anaconda3 for Windows 10 Home 64-bit PC)中提到的所有内容,但没有运气。我是蟒蛇的新手,我将非常感激自我学习的具体细节。
控制台:
Traceback (most recent call last):
from matplotlib import pyplot
File "C:\Users\...\lib\site-packages\matplotlib\pyplot.py", line 29, in <module>
import matplotlib.colorbar
File "C:\Users\...\lib\site-packages\matplotlib\colorbar.py", line 34, in <module>
import matplotlib.collections as collections
File "C:\Users\...\lib\site-packages\matplotlib\collections.py", line 27, in <module>
import matplotlib.backend_bases as backend_bases
File "C:\Users\...\lib\site-packages\matplotlib\backend_bases.py", line 62, in <module>
import matplotlib.textpath as textpath
File "C:\Users\...\lib\site-packages\matplotlib\textpath.py", line 15, in <module>
import matplotlib.font_manager as font_manager
File "C:\Users\...\lib\site-packages\matplotlib\font_manager.py", line 1421, in <module>
_rebuild()
File "C:\Users\...\lib\site-packages\matplotlib\font_manager.py", line 1406, in _rebuild
fontManager = FontManager()
File "C:\Users\...\lib\site-packages\matplotlib\font_manager.py", line 1044, in __init__
self.ttffiles = findSystemFonts(paths) + findSystemFonts()
File "C:\Users\...\lib\site-packages\matplotlib\font_manager.py", line 313, in findSystemFonts
for f in win32InstalledFonts(fontdir):
File "C:\Users\...\lib\site-packages\matplotlib\font_manager.py", line 231, in win32InstalledFonts
direc = os.path.abspath(direc).lower()
File "C:\Users\...\lib\ntpath.py", line 535, in abspath
path = _getfullpathname(path)
ValueError: _getfullpathname: embedded null character
的Python:
importing libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
#importing dataset
dataset = pd.read_csv('Position_Salaries.csv')
x = dataset.iloc[:,1:2].values
y = dataset.iloc[:,2].values
#Linear Regression
from sklearn.linear_model import LinearRegression
reg_lin = LinearRegression()
reg_lin = reg_lin.fit(x,y)
#ploynomial Linear Regression
from sklearn.preprocessing import PolynomialFeatures
reg_poly = PolynomialFeatures(degree = 3)
x_poly = reg_poly.fit_transform(x)
reg_poly.fit(x_poly,y)
lin_reg_2 = LinearRegression()
lin_reg_2.fit(x_poly,y)
#Visualizing Linear Regression results
plt.scatter(x,y,color = 'red')
plt.plot(x,reg_lin.predict(x), color = 'blue')
plt.title('Truth vs. Bluff (Linear Reg)')
plt.xlabel('Position level')
plt.ylabel('Salary')
plt.show()
#Visualizing Polynomial Regression results
plt.scatter(x,y,color = 'red')
plt.plot(x,lin_reg_2.predict(reg_poly.fit_transform(x)), color = 'blue')
plt.title('Truth vs. Bluff (Linear Reg)')
plt.xlabel('Position level')
plt.ylabel('Salary')
plt.show()
答案 0 :(得分:2)
在font_manager py:
中找到它direc = os.path.abspath(direc).lower()
将其更改为:
direc = direc.split('\0', 1)[0]
并保存以应用于您的文件。
答案 1 :(得分:0)
我认为你没有正确地在Error on import matplotlib.pyplot (on Anaconda3 for Windows 10 Home 64-bit PC)中应用补丁:如果你有,那么错误堆栈中不应该提到direc = os.path.abspath(direc).lower()
,因为补丁删除了它。
要清楚,这是应用补丁后win32InstalledFonts()
(或安装Anaconda的地方)中的整个C:\Anaconda\envs\py35\Lib\site-packages\matplotlib\font_manager.py
方法,使用matplotlib 2.0.0:
def win32InstalledFonts(directory=None, fontext='ttf'):
"""
Search for fonts in the specified font directory, or use the
system directories if none given. A list of TrueType font
filenames are returned by default, or AFM fonts if *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:
''' Patch fixing [Error on import matplotlib.pyplot (on Anaconda3 for Windows 10 Home 64-bit PC)](https://stackoverflow.com/a/34007642/395857)
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]
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
答案 2 :(得分:0)
问题的实际原因似乎在os.path.abspath()
。更好的解决方案可能是编辑<python dir>\Lib\ntpaths.py
ValueError:
基本上,将一个$sql = "INSERT INTO prescription(username,phone,procedure,address,emailid,reviews,followups,nextappointment)VALUES('$usernam','$phone','$procedure','$address','$emailid','$reviews','$followups','$nextappointment')";
异常处理程序添加到abspath()函数的Windows版本中。这在调用堆栈中较低,可以帮助您避免在其他地方遇到此问题。