Step 1: Locate the Python library
Run this in SSMS to find the Path where Python is installed on your SQL Server 2017:
--Get location of packages used by Python for SQL Server.
EXEC sp_execute_external_script
@language =N'Python',
@script=N'import sys; print("\n".join(sys.path))'
GO
Run the below 2 commands in CMD (Run as Administrator) on the Machine Where your SQL Server is Installed
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 pysftp
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.
https://stackoverflow.com/questions/61214462/how-to-install-and-update-python-libraries-into-sql-ml-server-instance
https://dzone.com/articles/adding-python-packages-to-sql-server-2017
https://sqlundercover.com/2018/09/03/installing-external-modules-into-sql-servers-python/
It allowed me to install but now getting this error when I try to run a simple:
EXECUTE sp_execute_external_script @language = N'Python'
, @script = N'
import pysftp as pftp
print("My Name")'
Any help appreciated:
Error:
Msg 39004, Level 16, State 20, Line 0
A 'Python' script error occurred during execution of 'sp_execute_external_script' with HRESULT 0x80004004.
Msg 39019, Level 16, State 2, Line 0
An external script error occurred:
Error in execution. Check the output for more information.
C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\paramiko\transport.py:33: CryptographyDeprecationWarning: Python 3.5 support will be dropped in the next release of cryptography. Please upgrade your Python.
from cryptography.hazmat.backends import default_backend
Traceback (most recent call last):
File "<string>", line 5, in <module>
File "C:\SQL-MSSQLSERVER-ExtensibilityData-PY\MSSQLSERVER01\0B77C9DC-6C37-4FEB-8F53-96AE65A1D675\sqlindb.py", line 29, in transform
import pysftp as pd
File "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\pysftp__init__.py", line 12, in <module>
import paramiko
File "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\paramiko__init__.py", line 22, in <module>
Msg 39019, Level 16, State 2, Line 0
An external script error occurred:
from paramiko.transport import SecurityOptions, Transport
File "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\paramiko\transport.py", line 129, in <module>
class Transport(threading.Thread, ClosingContextManager):
File "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\paramiko\transport.py", line 190, in Transport
if KexCurve25519.is_available():
File "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\paramiko\kex_curve25519.py", line 30, in is_available
X25519PrivateKey.generate()
File "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\cryptography\hazmat\primitives\asymmetric\x25519.py", line 39, in generate
from cryptography.hazmat.backends.openssl.backend import backend
Msg 39019, Level 16, State 2, Line 0
An external script error occurred:
File "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\cryptography\hazmat\backends\openssl__init__.py", line 7, in <module>
from cryptography.hazmat.backends.openssl.backend import backend
File "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\cryptography\hazmat\backends\openssl\backend.py", line 117, in <module>
from cryptography.hazmat.bindings.openssl import binding
File "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\cryptography\hazmat\bindings\openssl\binding.py", line 16, in <module>
from cryptography.hazmat.bindings._openssl import ffi, lib
ImportError: DLL load failed: The specified module could not be found.
SqlSatelliteCall error: Error in execution. Check the output for more information.
STDOUT message(s) from external script:
SqlSatelliteCall function failed. Please see the console output for more information.
Traceback (most recent call last):
File "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\revoscalepy\computecontext\RxInSqlServer.py", line 587, in rx_sql_satellite_call
rx_native_call("SqlSatelliteCall", params)
File "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\revoscalepy\RxSerializable.py", line 358, in rx_native_call
ret = px_call(functionname, params)
RuntimeError: revoscalepy function failed.
Completion time: 2021-02-24T17:44:54.7788833+11:00