1

I'm running SQL Server 2017 developer edition with Machine Learning Services (python V3.5.2). I got everything set up today and can successfully run sp_execute_external_script like the following:

EXEC sp_execute_external_script
  @language =N'Python',
  @script=N'
print ("Hello World")'

I then installed the yfinance module to a directory that is listed in sys.path, and I can confirm that the server recognizes the installed package by running the following code in SQL Server:

EXECUTE sp_execute_external_script 
  @language = N'Python', 
  @script = N'
import pkg_resources
import pandas as pd
installed_packages = pkg_resources.working_set
installed_packages_list = sorted(["%s==%s" % (i.key, i.version) for i in installed_packages])
df = pd.DataFrame(installed_packages_list)
OutputDataSet = df
'
WITH RESULT SETS (( PackageVersion nvarchar (150) ))

At the bottom of the list it shows an output for "yfinance==0.1.54". However, when I try to import the package using the code below, I get an error that says "ImportError: No module named 'yfinance'":

EXEC sp_execute_external_script
  @language =N'Python',
  @script=N'import yfinance'

I tried running Python.exe directly from C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES, and from there I am able to successfully run "import yfinance".

What am I missing here? How else can I troubleshoot why yfinance will not work through sp_execute_external_script?

Chris
  • 21
  • 2
  • Our team has been running into similar issues with installing/managing packages. What technique did you use to install the new package? Did you use `pip` or `conda` directly on the host server or did you use [`sqlmlutils`](https://github.com/microsoft/sqlmlutils/tree/master/Python)? – yanniskatsaros Feb 01 '21 at 18:07

0 Answers0