python - 如何使用 Azure Blob 存储挂载数据?

标签 python azure azure-blob-storage azure-databricks

我是 Azure Databricks 的新手,我的导师建议我完成机器学习训练营

https://aischool.microsoft.com/en-us/machine-learning/learning-paths/ai-platform-engineering-bootcamps/custom-machine-learning-bootcamp

不幸的是,在成功设置 Azure Databricks 后,我在步骤 2 中遇到了一些问题。我成功将 1_01_introduction 文件作为笔记本添加到我的工作区。然而,虽然本教程讨论了如何在 Azure Blob 存储中挂载数据,但它似乎跳过了该步骤,这导致接下来的所有教程编码步骤都会抛出错误。第一个代码位(教程告诉我运行)以及随后出现的错误包含在下面。

%运行“../presenter/includes/mnt_blob”

找不到笔记本:presenter/includes/mnt_blob。笔记本可以通过相对路径(./Notebook 或 ../folder/Notebook)或绝对路径(/Abs/Path/to/Notebook)指定。确保您指定的路径正确。

堆栈跟踪: /1_01_简介:Python

据我所知,Azure Blob 存储尚未设置,因此我运行的代码(以及以下所有步骤中的代码)无法找到以下教程项目:应该存储在 blob 中。各位好心人可以提供的任何帮助将不胜感激。

最佳答案

在 Azure Databricks 中设置和安装 Blob 存储需要执行几个步骤。

首先,create a storage account然后create a container里面。

接下来,记下以下项目:

  • 存储帐户名称:创建存储帐户时的名称
  • 存储帐户 key :可以在资源页面的 Azure 门户中找到。
  • 容器名称:容器的名称

在 Azure Databricks 笔记本中,为上述项目创建变量。

storage_account_name = "Storage account name"
storage_account_key = "Storage account key"
container = "Container name"

然后,使用以下代码设置 Spark 配置以指向您的 Azure Blob 存储实例。

spark.conf.set("fs.azure.account.key.{0}.blob.core.windows.net".format(storage_account_name), storage_account_key)

要将其装载到 Azure Databricks,请使用dbutils.fs.mount 方法。源是 Azure Blob 存储实例和特定容器的地址。装载点是将其装载到 Azure Databricks 上的 Databricks 文件存储中的位置。额外的配置是您传递 Spark 配置的位置,因此并不总是需要设置它。

dbutils.fs.mount(
 source = "wasbs://{0}@{1}.blob.core.windows.net".format(container, storage_account_name),
 mount_point = "/mnt/<Mount name>",
 extra_configs = {"fs.azure.account.key.{0}.blob.core.windows.net".format(storage_account_name): storage_account_key}
)

完成这些设置后,您现在可以开始使用安装座了。要检查它是否可以查看存储帐户中的文件,请使用 dbutils.fs.ls 命令。

dbutils.fs.ls("dbfs:/mnt/<Mount name>")

希望有帮助!

关于python - 如何使用 Azure Blob 存储挂载数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56774393/

相关文章:

azure - Azure Blob 存储是否有默认图像类型?

python - 正确使用注释

python - Python 中的嵌套字符串替换为正则表达式

azure - 如何仅获取 Azure key 保管库的部分 Powershell 输出?

azure - 更新现有 azure 注册表的镜像不起作用

java - Azure Blob存储: CloudBlockBlob. downloadToByteArray(byte[] buffer, int bufferOffset)如何设置缓冲区大小

c# - 微软Azure : How to create sub directory in a blob container

python - 过滤特定语音部分 NLTK

python - 填充不保留所有列

azure - 将集成运行时名称作为参数包含在数据工厂的 ARM 模板中