【问题标题】:Enable Python in SQL Server 2017在 SQL Server 2017 中启用 Python
【发布时间】:2019-10-06 00:29:36
【问题描述】:

我已经执行了以下命令:

 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 服务包吗?请建议。 谢谢。

【问题讨论】:

  • 那不是你的SQL Server版本,那是SSMS的版本;这是完全无关的。使用 PRINT @@VERSION; 获取您的 SQL Server 版本。
  • 用 SQL 版本更新了我的问题。

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


【解决方案1】:
  1. 检查文件夹“PYTHON_SERVICES”及其在以下路径中的可用内容:

[驱动器名称]:\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 将“启用外部脚本”值设置为 1,然后重新启动 SQL Server 实例。 3.1。右键单击您的 SQL Server,然后单击“重新启动”。

  3. 成功重启服务后,检查配置值启用/禁用:

select * from sys.sysconfigures where 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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多