Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将外部python模块与SQL 2017 sp_execute_外部_脚本一起使用?_Python_Sql Server - Fatal编程技术网

如何将外部python模块与SQL 2017 sp_execute_外部_脚本一起使用?

如何将外部python模块与SQL 2017 sp_execute_外部_脚本一起使用?,python,sql-server,Python,Sql Server,我正在测试SQL 2017机器学习服务,它允许您在存储过程中运行python脚本。我看到了很多关于在存储过程本身中定义python脚本时如何运行该脚本的示例,但是我想知道如何导入我自己的python模块。大概是这样的: EXEC sp_execute_external_script @language = N'Python', @script = N' from test import sample x = sample.SomeClass() x.SomeFunction() ' 这可能吗?

我正在测试SQL 2017机器学习服务,它允许您在存储过程中运行python脚本。我看到了很多关于在存储过程本身中定义python脚本时如何运行该脚本的示例,但是我想知道如何导入我自己的python模块。大概是这样的:

EXEC sp_execute_external_script
@language = N'Python',
@script = N'
from test import sample
x = sample.SomeClass()
x.SomeFunction()
'

这可能吗?是否有其他方法可以让我在SQL中运行自己的python脚本?

是的,您可以通过在代码中添加
test
模块的位置来扩展sys.path环境变量,如下所示

EXEC sp_execute_external_script
@language = N'Python',
@script = N'
import sys
sys.path += ['D:\\path_to_your_test_module']
from test import sample as sa
x = sa.SomeClass()
x.SomeFunction()
'

@据我所知,MitchWheat只允许我导入一个已安装到服务器上的公共模块。我不确定这个方法是否允许我导入我自己编写的私有模块?太棒了,希望几个月前我需要你的时候你在那里!别开玩笑了,谢谢你。希望这能帮助其他人。