Error when execute python script from sql server 2017query

when run python script from sql server 2017 I get error

Msg 39004, Level 16, State 20, Line 0
A 'Python' script error occurred during execution of 'sp_execute_external_script' with HRESULT 0x80004004.
Msg 39019, Level 16, State 2, Line 0
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 "D:\ProgramData\MSSQLSERVER\Temp-PY\Appcontainer1\3E1B378D-D357-4C9C-991B-F07D4A51A5AC\sqlindb_0.py", line 31, in transform
    for i in pip.get_installed_distributions():
AttributeError: module 'pip' has no attribute 'get_installed_distributions'

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 "D:\SQL Data\MSSQL15.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\revoscalepy\computecontext\RxInSqlServer.py", line 605, in rx_sql_satellite_call
    rx_native_call("SqlSatelliteCall", params)
  File "D:\SQL Data\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.

so how to solve issue please ?

when install sql server 2017 i add python option

What I have tried:

EXECUTE sp_execute_external_script
@language =N'Python',
@script=N'import pip
for i in pip.get_installed_distributions():
    print(i)';
GO

This has nothing to do with SQL server. Might be a good question for a python forum.

1 Like