SQL Server Machine Learning Service comes with a default Phyton runtime. For SQL 2019, it’s Phyton 3.5. You might need to run your Phyton script against a different version of Phyton runtime.
To configure another Phyton version runtime to be available to your SQL instance, do the following:
- Install Phyton 3.10 with options to install for all users
- Install required packages
- Grant required permissions to SQL Server LaunchPad service
@ECHO OFF
ECHO installing python
"%~dp0python-3.10.11-amd64.exe" /passive TargetDir="C:\Program Files\Python310" InstallAllUsers=1 PrependPath=1 Include_test=0
ECHO installing required packages
"C:\Program Files\Python310\python.exe" -m pip install -t "C:\Program Files\Python310\Lib\site-packages" dill numpy pandas patsy python-dateutil
"C:\Program Files\Python310\python.exe" -m pip install -t "C:\Program Files\Python310\Lib\site-packages" https://aka.ms/sqlml/python3.10/windows/revoscalepy-10.0.1-py3-none-any.whl
ECHO grant required permissions
icacls "C:\Program Files\Python310" /grant "NT Service\MSSQLLAUNCHPAD$SQLEXP_2019":(OI)(CI)RX /T
icacls "C:\Program Files\Python310" /grant *S-1-15-2-1:(OI)(CI)RX /T
Please note, in the above script for grant required permission section, change MSSQLLAUNCHPAD$SQLEXP_2019 to the account running lauchpad service.
In the above script, assign permission to S-1-15-2-1 is equivelant to assign permission to ALL APPLICATION PACKAGES.
Reference resources:
What is SQL Server Machine Learning Services with Python and R?Install a Python custom runtime for SQL Server
Install SQL Server 2022 Machine Learning Services (Python and R) on Windows
Install packages with Python tools on SQL Server
Change the default R or Python language runtime version