gpt4 book ai didi

azure pyspark from 模块导入 myfunctions;无模块名称

转载 作者:行者123 更新时间:2023-12-03 00:22:47 24 4
gpt4 key购买 nike

我尝试了多种方法来从我们的共享团队目录导入包含一堆共享函数的本地脚本,示例如下所示。我还尝试了在同一目录中使用导入脚本的“from .importsharedFunctions”和从父目录中的“fromsharedModulesimportsharedFunctions”。根据一些谷歌搜索,所有这些都返回 No module named 'sharedFunctions' 。在 Azure 中设置此功能的最佳方法是什么?

谢谢

import sys, os
dir_path = '/Shared/XXX/sharedModules'
sys.path.insert(0, dir_path)
print(sys.path)
# dir_path = os.path.dirname(os.path.realpath(__file__))
# sys.path.insert(0, dir_path)
import sharedFunctions

sourceTable='dnb_raw'
sourceQuery='select DUNSNumber , GlobalUltimate_Name, BusinessName from'
sourceId = 'DUNSNumber'
sourceNameList=['Tradestyle','BusinessName']
NewTable = 'default.' + sourceTable + '_enhanced'
#dbutils.fs.rm("dbfs:/" + NewTable + "/",recurse=True)
clean_names(sourceTable,sourceQuery,sourceId,sourceNameList)

最佳答案

当您在 Databricks 中使用笔记本时,它们并不位于 Python 理解为模块的某些文件系统上。

如果您想将另一个具有其他定义的笔记本包含到当前上下文中,可以使用 %run magic command ,传递另一个笔记本的名称作为参数:

%run /Shared/XXX/sharedModules/sharedFunctions

但是 %run 并不是导入的完全替代,如文档中所述

You cannot use %run to run a Python file and import the entities defined in that file into a notebook. To import from a Python file you must package the file into a Python library, create a Databricks library from that Python library, and install the library into the cluster you use to run your notebook.

如果您想执行另一个笔记本以从中获取一些结果,您可以使用所谓的 notebook workflow - 当通过dbutils.notebook.run执行时,笔记本被安排执行,您可以向它传递一些参数等,但结果将主要通过文件系统、托管表等共享。

关于azure pyspark from 模块导入 myfunctions;无模块名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65632299/

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