0

I'm trying to 'import datefinder' in my SQL Server Python script, but for some reason it doesn't work. Other libraries (for example Pandas) seem to work just fine.

I've tried following script in Python;

 import sqlmlutils  
 connection = sqlmlutils.ConnectionInfo(server="xxx", database="xxx")
 sqlmlutils.SQLPackageManager(connection).install("datefinder")

And receive following error message;

MSSQLDatabaseException: (20009, b'DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (xxx\xxx)\n')

When I try to run my script in SQL Server I get following error;

Msg 39004, Level 16, State 20, Line 1 A 'Python' script error occurred during execution of 'sp_execute_external_script' with HRESULT 0x80004004. Msg 39019, Level 16, State 2, Line 1 An external script error occurred:

Error in execution. Check the output for more information. Traceback (most recent call last): File "", line 5, in File "C:\PROGRA~1\MICROS~4\MSSQL1~1.DEV\MSSQL\EXTENS~1\DEV201701\64B0BBDF-3497-42E2-8C54-38CA1EA8CD85\sqlindb.py", line 37, in transform import datefinder ImportError: No module named 'datefinder'

SqlSatelliteCall error: Error in execution. Check the output for more information.

1 Answer 1

0

https://thomaslarock.com/2018/05/adding-python-packages-to-sql-server-2017/

Best explanation I could ever find !

EXEC sp_execute_external_script
  @language =N'Python',
  @script=N'import sys; print("\n".join(sys.path))'

Lets you retrieve the path to the python environment used by SQL Server:

C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER2017\PYTHON_SERVICES\lib\site-packages\setuptools-27.2.0-py3.5.egg

Open a command line, navigate down to your PYTHON_SERVICES/Scripts directory. From there, call pip install datefinder You will need to have the rights to do this.

Sign up to request clarification or add additional context in comments.

1 Comment

If you get the SSL error at this point it's because your SQL Server machine has no SSL installed. Installing OpenSSL works well for some.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.