How can I use an external python module with SQL 2017 sp_execute_external_script?

后端 未结 1 1393
天命终不由人
天命终不由人 2021-01-20 03:39

I\'m testing out the SQL 2017 machine learning services that allow you to run python scripts in a stored procedure. I see plenty of examples of how to run a python script w

1条回答
  •  醉话见心
    2021-01-20 04:16

    Yes you may do this by extending the sys.path environment variables by the adding the location of test module in your code like this

    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()
    '
    

    0 讨论(0)
提交回复
热议问题