Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to:
SQL Server 2017 (14.x) only
This article describes how to use standard Python tools to install new Python packages on an instance of SQL Server Machine Learning Services. In general, the process for installing new packages is similar to that in a standard Python environment. However, some additional steps are required if the server does not have an Internet connection.
For more information about package location and installation paths, see Get Python package information.
Packages must be Python 3.5-compliant and run on Windows.
The Python package library is located in the Program Files folder of your SQL Server instance and, by default, installing in this folder requires administrator permissions. For more information, see Package library location.
Package installation is per instance. If you have multiple instances of Machine Learning Services, you must add the package to each one.
Database servers are frequently locked down. In many cases, Internet access is blocked entirely. For packages with a long list of dependencies, you will need to identify these dependencies in advance and be ready to install each one manually.
Before adding a package, consider whether the package is a good fit for the SQL Server environment.
We recommend that you use Python in-database for tasks that benefit from tight integration with the database engine, such as machine learning, rather than tasks that simply query the database.
If you add packages that put too much computational pressure on the server, performance will suffer.
On a hardened SQL Server environment, you might want to avoid the following:
To install a new Python package that can be used in a script on SQL Server, you install the package in the instance of Machine Learning Services. If you have multiple instances of Machine Learning Services, you must add the package to each one.
The package installed in the following examples is CNTK, a framework for deep learning from Microsoft that supports customization, training, and sharing of different types of neural networks.
If you are installing Python packages on a server with no Internet access, you must download the WHL file from a computer with Internet access and then copy the file to the server.
For example, on an Internet-connected computer you can download a .whl
file for CNTK and then copy the file to a local folder on the SQL Server computer. See Install CNTK from Wheel Files for a list of available .whl
files for CNTK.
Important
Make sure that you get the Windows version of the package. If the file ends in .gz, it's probably not the right version.
For more information about downloads of the CNTK framework for multiple platforms and for multiple versions of Python, see Setup CNTK on your machine.
Locate the default Python library location used by SQL Server. If you have installed multiple instances, locate the PYTHON_SERVICES
folder for the instance where you want to add the package.
For example, if Machine Learning Services was installed using defaults, and machine learning was enabled on the default instance, the path is:
cd "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES"
Tip
For future debugging and testing, you might want to set up a Python environment specific to the instance library.
Use the pip installer to install new packages. You can find pip.exe
in the Scripts
subfolder of the PYTHON_SERVICES
folder. SQL Server Setup does not add the Scripts
subfolder to the system path, so you must specify the full path, or you can add the Scripts folder to the PATH variable in Windows.
Note
If you're using Visual Studio 2017, or Visual Studio 2015 with the Python extensions, you can run pip install
from the Python Environments window. Click Packages, and in the text box, provide the name or location of the package to install. You don't need to type pip install
; it is filled in for you automatically.
If the computer has Internet access, provide the name of the package:
scripts\pip.exe install cntk
You can also specify the URL of a specific package and version, for example:
scripts\pip.exe install https://cntk.ai/PythonWheel/CPU-Only/cntk-2.1-cp35-cp35m-win_amd64.whl
If the computer does not have Internet access, specify the WHL file you downloaded earlier. For example:
scripts\pip.exe install C:\Downloads\cntk-2.1-cp35-cp35m-win_amd64.whl
You might be prompted to elevate permissions to complete the install. As the installation progresses, you can see status messages in the command prompt window.
When installation is complete, you can immediately begin using the package in Python scripts in SQL Server.
To use functions from the package in your script, insert the standard import <package_name>
statement in the initial lines of the script:
EXECUTE sp_execute_external_script
@language = N'Python',
@script = N'
import cntk
# Python statements ...
'
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayTraining
Certification
Microsoft Certified: Azure Data Scientist Associate - Certifications
Manage data ingestion and preparation, model training and deployment, and machine learning solution monitoring with Python, Azure Machine Learning and MLflow.
Documentation
Set up a Python data science client - SQL Server Machine Learning Services
Set up a Python local environment (Jupyter Notebook or PyCharm) for remote connections to SQL Server Machine Learning Services with Python.
Install Python packages with sqlmlutils - SQL Server Machine Learning Services
Learn how to use Python pip to install new Python packages on an instance of SQL Server Machine Learning Services.
Quickstart: Run Python scripts - SQL machine learning
Run a set of simple Python scripts using Machine Learning Services on SQL Server, Big Data Clusters, or Azure SQL Managed Instances. Learn how to use the stored procedure sp_execute_external_script to execute the script.