pythonsql-serversql-server-ml-services

How to install and update Python Libraries into SQL ML Server instance?


I have a problem with upgrading and installing python packages on SQL Server Machine Learning Services in in-database instance. I have tried both in-database installation using pip (from the proper instance) and remote client installation using sqlmlutils library. To be more precise I had a problem when I tried to fit a model using statsmodels.tsa.statespace.SARIMAX library and I got following error: Invalid BXL stream error while running BxlServer: caught exception: Error communicating between BxlServer and client: 0x000000e9

So I thought an update of the library will help. First I struggled to update it with sqlmlutils through the remote client where I got this error: ('08S01', '[08S01] [Microsoft][ODBC SQL Server Driver]Communication link failure (0) (SQLEndTran)')

I succeeded with pip install but when I tried to import it in SSMS once more (because statsmodels updates the pandas library also) I had a new error: Unable to communicate with the runtime for 'Python' script for request id: C3DCF376-3B87-4C3C-9BE5-125ACD788EB4. Please check the requirements of 'Python' runtime.” “ImportError: cannot import name 'DataFrame' from 'pandas' (unknown location)

Further more I tried to install fbprophet library using pip install and I got this error:

  Failed building wheel for fbprophet
  Running setup.py clean for fbprophet
Failed to build fbprophet
tables 3.5.1 requires mock>=2.0, which is not installed.
nltk 3.4 requires singledispatch, which is not installed.
Installing collected packages: Cython, numpy, six, python-dateutil, pytz, pandas, cmdstanpy, pystan, pyparsing, kiwisolver, cycler, matplotlib, ephem, LunarCalendar, pymeeus, convertdate, korean-lunar-calendar, holidays, setuptools-git, fbprophet
  Running setup.py install for fbprophet ... error
    Complete output from command "C:\Program Files\Microsoft SQL Server\MSSQL15.MLSERVER\PYTHON_SERVICES\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\Marko\\AppData\\Local\\Temp\\pip-install-wyjwmusv\\fbprophet\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\Marko\AppData\Local\Temp\pip-record-g_krzlzj\install-record.txt --single-version-externally-managed --compile --home=C:\Users\Marko\AppData\Local\Temp\pip-target-zavyou39:
    running install
    running build
    running build_py
    creating build
    creating build\lib
    creating build\lib\fbprophet
    creating build\lib\fbprophet\stan_model
    Importing matplotlib failed. Plotting will not work.
    Importing plotly failed. Interactive plots will not work.

Finally I tried the to upgrade whole Python package using “binding” with Machine Learning Server app. That also failed with an error: The instance must have a compatible version of SQL R Services (in-DB) installed.

I follow all the install instruction from the following link: https://learn.microsoft.com/en-us/sql/machine-learning/install/sql-machine-learning-services-windows-install?view=sql-server-ver15

Thanks in advance.


Solution

  • Step 1: Locate the Python library

    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"
    

    Step 2: Install the package using pip

    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.

    scripts\pip.exe install nltk
    

    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.