January 3, 2022 at 3:43 pm
There are likely to be several unrelated errors here, but I'm going to start with the first one what I can get my mind around. I'm trying to use the "Python within SQL Server" mechanism to generate a barchart to PDF. I get an error message that I don't have permissions to the directory I'm aiming for. I've set the permissions to full control for that directory for every user in my system (my home desktop). I'm using SQL Server Developer, btw. Here is my code, which I'm trying to adapt from this website:
SQL Server Machine Learning Services – Part 3: Plotting Data with Python - Simple Talk (red-gate.com)
I know this is kinda obscure, but if anyone had any input, most appreciated.
use AdventureWorks2019
DECLARE @sqlscript NVARCHAR(MAX);
SET @sqlscript = N'Select TaxRate from Sales.SalesTaxRate'
EXECUTE sp_execute_external_script
@language = N'Python',
@script=N'
# import matplotlib modules
import matplotlib
matplotlib.use("PDF")
import matplotlib.pyplot as plt
# define df data frame
df = InputDataSet
# create bar chart object
pt = df.plot.barh()
# save bar chart to PDF file
plt.savefig("C:\\DataFiles\\Taxrate.pdf")',
@input_data_1 = @sqlscript;
Here are my error messages:
Msg 39004, Level 16, State 20, Line 1
A 'Python' script error occurred during execution of 'sp_execute_external_script' with HRESULT 0x80004004.
Msg 39019, Level 16, State 2, Line 1
An external script error occurred:
Error in execution. Check the output for more information.
Traceback (most recent call last):
File "<string>", line 5, in <module>
File "C:\ProgramData\MSSQLSERVER\Temp-PY\Appcontainer1\05CC5857-66A5-4ADE-A40C-CFFFB16651F4\sqlindb_0.py", line 55, in transform
plt.savefig("C:\\DataFiles\\Taxrate.pdf")
File "C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\matplotlib\pyplot.py", line 689, in savefig
res = fig.savefig(*args, **kwargs)
File "C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\matplotlib\figure.py", line 2094, in savefig
self.canvas.print_figure(fname, **kwargs)
File "C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\matplotlib\backend_bases.py", line 2075, in print_figure
**kwargs)
Msg 39019, Level 16, State 2, Line 1
An external script error occurred:
File "C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\matplotlib\backends\backend_pdf.py", line 2558, in print_pdf
file = PdfFile(filename, metadata=metadata)
File "C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\matplotlib\backends\backend_pdf.py", line 433, in __init__
fh, opened = cbook.to_filehandle(filename, "wb", return_opened=True)
File "C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\matplotlib\cbook\__init__.py", line 392, in to_filehandle
fh = open(fname, flag, encoding=encoding)
PermissionError: [Errno 13] Permission denied: 'C:\\DataFiles\\Taxrate.pdf'
SqlSatelliteCall error: Error in execution. Check the output for more information.
STDOUT message(s) from external script:
SqlSatelliteCall function failed. Please see the console output for more information.
Traceback (most recent call last):
File "C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\revoscalepy\computecontext\RxInSqlServer.py", line 605, in rx_sql_satellite_call
rx_native_call("SqlSatelliteCall", params)
File "C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\revoscalepy\RxSerializable.py", line 375, in rx_native_call
ret = px_call(functionname, params)
RuntimeError: revoscalepy function failed.
January 5, 2022 at 2:50 pm
This was removed by the editor as SPAM
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply