SQL Server Python integration

Posted by John Liu on Friday, December 23, 2022

SQL Server Machine Learning Services config files are located under C:\Program Files\Microsoft SQL Server\MSSQL15.SQLEXP_2019\MSSQL\Binn pythonlauncher.config rlauncher.config

When receive following error SQL Python LaunchPad Error

  1. If the service worked before but not now, check the LaunchPad service has been restarted following restart of SQL Instance.
  2. If restart SQL Instance followed by restart LaunchPad service didn’t help, check LaunchPad service account has FULL CONTROL permission on the working folder configured in the above config file

From SQL2019, the working folder in the config file is a shortcut link to C:\Program Files\Microsoft SQL Server\MSSQL15.SQLEXP_2019\MSSQL\ExtensibilityData

To check the current Phython version:

EXECUTE sp_execute_external_script @language = N'Python'
    , @script = N'
import sys
print(sys.version)
'

To check Phython packages installed:

EXECUTE sp_execute_external_script @language = N'Python'
    , @script = N'
import pkg_resources
import pandas
dists = [str(d) for d in pkg_resources.working_set]
OutputDataSet = pandas.DataFrame(dists)
'
WITH RESULT SETS(([Package] NVARCHAR(max)))

To install Python packages, run the following command with Administrator permission. pip.exe is located under C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\PYTHON_SERVICES\Scripts

pip install <packagename>

To install a Python package with a specific version (for example version 3.4.1):

pip install <packagename>==3.4.1

When using pip to install package, you might encounter following error related to ssl module: Python pip TLS/SSL error To fix the issue, copy following files fronm C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\PYTHON_SERVICES\Library\bin to C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\PYTHON_SERVICES\DLLs

  • libcrypto-1_1-x64.dll
  • libcrypto-1_1-x64.pdb
  • libssl-1_1-x64.dll
  • libssl-1_1-x64.pdb