gpt4 book ai didi

python - sp_execute_external_script 找不到 setuptools 安装的模块

转载 作者:太空宇宙 更新时间:2023-11-03 19:54:30 28 4
gpt4 key购买 nike

我正在积极开发一个Python模块,我想将其部署在本地安装的SQL Server 2017中,因此我将该模块部署在c:\Program Files\Microsoft SQL Server\<Instance Name>\PYTHON_SERVICES\Lib\site-packages中使用setuptools像这样:

"c:\Program Files\Microsoft SQL Server\<Instance_Name>\PYTHON_SERVICES\python" setup.py develop

这会产生 .egg-info我的项目根目录中的目录,以及 .egg-link文件在 site-packages上面提到的目录。 .egg-link文件正确指向.egg-info我的项目根目录中的目录,所以它出现 setuptools工作正常。

这是我的 setup.py供引用:

from setuptools import setup

setup(
setup_requires=['pbr'],
pbr=True,
)

这是相应的setup.cfg文件:

[metadata]
name = <module_name>
description = <Module Description>
description-file = README.md
description-content-type = text/markdown

[files]
package_root = py/src

由于我只是想让管道工作,所以我有一个名为 uploader.py 的 python 脚本。在<project_root>/py/src :

#uploader.py
class Upload:
pass

部署到位后,我希望能够简单地import我刚刚通过.egg-link发布的模块进入sp_execute_external_script像这样调用:

execute sp_execute_external_script @language= N'Python', @script= N'from <module_name>.uploader import Upload';

但是,从 SSMS 执行此存储过程会产生以下错误消息:

Msg 39004, Level 16, State 20, Line 10
A 'Python' script error occurred during execution of 'sp_execute_external_script' with HRESULT 0x80004004.
Msg 39019, Level 16, State 2, Line 10
An external script error occurred:

Error in execution. Check the output for more information.
Traceback (most recent call last):
File "<string>", line 5, in <module>
File "C:\SQL-MSSQLSERVER-ExtensibilityData-PY\MSSQLSERVER01\C08BB9A7-66B5-4B5E-AAFC-B0248EE64199\sqlindb.py", line 27, in transform
from <module_name>.uploader import Upload
ImportError: No module named '<module_name>'

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\<Instance_Name>\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\<Instance_Name>\PYTHON_SERVICES\lib\site-packages\revoscalepy\RxSerializable.py", line 358, in rx_native_call
ret = px_call(functionname, params)
RuntimeError: revoscalepy function failed.

我显然已经编辑了module_nameInstance_Name从错误消息中。

我尝试使用install命令而不是 develop只是为了确保 .egg-link文件不是问题。 install安装.egg-info文件在 site-packages但我得到了同样的错误。

我还尝试删除 pbr从混合中,但得到了同样的错误。

最后,我尝试添加我的 <project_root>sys.path根据How can I use an external python module with SQL 2017 sp_execute_external_script?的建议,但这也没有帮助。

所以在这一点上,我不知道我可能做错了什么。

python版本是3.5.2我不认为__init__.py项目中需要它才有资格作为模块。插入空白 __init__.pypy/src也没有帮助。

我的pip版本是19.3.1setuptools版本是44.0.0pbr版本是5.4.4我已经确认所有模块都安装在site-packages中上面提到的目录。

最佳答案

根据我的大量实验,看来 sp_execute_external_script不遵循符号链接(symbolic link)(即通过 .egg-link 文件)。因此,无论您使用setuptools,开发模式安装都将不起作用。 , pip , pbr或其他任何东西。

我什至尝试过符号链接(symbolic link) <package_name>文件夹作为操作系统符号链接(symbolic link)。由于我使用的是 Windows,因此我使用了 mklink /D命令提示符下的命令到符号链接(symbolic link) /py/src/<package_name>里面site-packages 。当命令正确执行时,我可以在文件资源管理器中看到符号链接(symbolic link)的文件夹,sp_execute_external_script无法检测到该包。这告诉我sp_execute_external_script中可能有东西。避免遍历符号链接(symbolic link)的代码。

我想知道是否有办法让它遍历符号链接(symbolic link)。

唯一可行的解​​决方案是在其自己的目录下开发包的代码,因此,就我而言 /py/src/<package_name> 。然后,在运行exec sp_execute_external_script @language=N'python', @script=N'...'之前复制<package_name>文件夹到site-packages目录。

这有点相当于 setup.py install ,但绕过中间文件和目录的创建。所以我将坚持这种简单但令人厌恶的方法。

我希望有更多知识的人能够提供更好的方法来解决这个问题。

关于python - sp_execute_external_script 找不到 setuptools 安装的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59616530/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com