在SQL Server 2017中启用Python

时间:2019-05-19 11:28:01

标签: python sql-server sql-server-2017

我已经执行了以下命令:

 EXEC sp_configure 'external scripts enabled', 1
 RECONFIGURE WITH OVERRIDE

从消息看来一切成功:

 Configuration option 'external scripts enabled' changed from 1 to 1. Run the RECONFIGURE statement to install.

但是,在以下脚本中执行时,显示错误:

exec sp_execute_external_script 
@language =N'Python',
@script=N'OutputDataSet = InputDataSet
print("Input data is {0}".format(InputDataSet))', 
@input_data_1 = N'SELECT 1 as col'

错误:

   Msg 39023, Level 16, State 1, Procedure sp_execute_external_script, Line 1 [Batch Start Line 7]
 'sp_execute_external_script' is disabled on this instance of SQL Server. Use sp_configure 'external scripts enabled' to enable it.

当我执行时:exec sp_configure

它显示“启用了外部脚本” run_value为0

当我通过运行更新查询来更新“运行值”时:

 update sys.configurations set value_in_use = 1
 where name like 'external scripts enabled'

获取错误:

  Ad hoc updates to system catalogs are not allowed.

以下是系统详细信息(来自SSMS帮助->关于):

  SQL Server Management Studio          15.0.18118.0
  Microsoft Analysis Services Client Tools  15.0.1300.131
  Microsoft Data Access Components (MDAC)   10.0.17134.1
  Microsoft MSXML                       3.0 6.0 
  Microsoft Internet Explorer           9.11.17134.0
  Microsoft .NET Framework              4.0.30319.42000
  Operating System                      6.3.17134

Microsoft SQL Server 2017 (RTM-CU14) (KB4484710) - 14.0.3076.1 (X64) 
Mar 12 2019 19:29:19 
Copyright (C) 2017 Microsoft Corporation
Developer Edition (64-bit) on Windows 10 Home 10.0 <X64> (Build 17134: )

此外,尝试从此处(https://www.microsoft.com/en-us/download/details.aspx?id=56128)安装SQL Server最新更新。

Python安装失败。

如何解决此问题并在SQL Server 2017上运行python?我是否需要安装任何SQL Server Service Pack?请提出建议。 谢谢。

2 个答案:

答案 0 :(得分:0)

在SQL Server 2017上,运行EXEC sp_configure 'external scripts enabled', 1 RECONFIGURE WITH OVERRIDE后,需要重新启动实例。

答案 1 :(得分:0)

  1. 检查文件夹“ PYTHON_SERVICES”及其内容在以下路径中可用:

[DriveName]:\ Program Files \ Microsoft SQL Server \ MSSQL14。[YOUR_INSTANCE_NAME] \ PYTHON_SERVICES

  1. 如果不存在,请通过以下链接进行安装: https://docs.microsoft.com/en-us/sql/advanced-analytics/install/sql-machine-learning-services-windows-install?view=sql-server-2017

  2. 如果存在上述文件夹,则需要通过运行sp_configure proc,然后重新启动SQL Server实例,将“启用外部脚本”的值设置为1。 3.1。右键单击您的SQL Server,然后单击“重新启动”。

  3. 成功重新启动服务后,请检查已启用/已禁用的配置值:

从sys.sysconfigures中选择*,其中comment ='允许执行外部脚本' 去

“值”列应为1。

  1. 如果“值”列设置为1,则可以执行外部脚本,例如来自SSMS的“ R”或“ Python”。

尝试在下面运行,看看是否返回的结果都没有任何错误:

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

exec sp_execute_external_script
   @language=N'R'
 , @script=N'print(R.version)'
 go