You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Azurite本地测试Polars?多种尝试均未成功

Polars 无法与 Azurite 本地存储交互的解决方案

问题复现

Azurite 提供的本地文件 URI 为 http://127.0.0.1/devstoreaccount/{container_name},但 Polars 无法正常读取该路径下的文件,尝试以下操作均未解决:

  • 直接使用 Azurite 提供的 localhost URL 访问
  • 添加 azure_storage_use_emulator 存储选项参数
  • 通过 Azurite 本地目录(启动参数 --hns --loose)的绝对路径访问

可行解决方法

1. 配置完整的 Azure 模拟器存储参数

Polars 依赖 fsspec 处理云存储交互,必须明确指定模拟器的默认账户信息和端点 URL,示例代码:

import polars as pl

# Azurite 默认账户信息,无需修改(除非你自定义过)
storage_options = {
    "account_name": "devstoreaccount1",
    "account_key": "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==",
    "azure_storage_emulator": True,
    "endpoint_url": "http://127.0.0.1:10000"
}

# 读取容器内的目标文件
df = pl.read_csv("az://{container_name}/your_target_file.csv", storage_options=storage_options)

注意:Azurite 默认的 Blob 服务端口是 10000,若启动时修改过端口,需同步调整 endpoint_url 中的端口号

2. 直接访问 Azurite 本地存储目录(适配 HNS 模式)

当 Azurite 以 --hns --loose 参数启动时,本地存储的目录结构为 {你的Azurite数据目录}/blobstorage/devstoreaccount1/{container_name}/,直接用这个绝对路径即可让 Polars 读取文件:

import polars as pl

# 替换为你的 Azurite 实际数据路径
local_azurite_path = "/Users/xxx/azurite_data/blobstorage/devstoreaccount1/my_container/data.csv"
df = pl.read_csv(local_azurite_path)

可以通过 Azurite 启动日志找到 BlobStorage 的根目录,或者直接在文件管理器中搜索容器名称定位路径

3. 排查 Azurite 服务状态

  • 先确认 Azurite 服务正常运行:访问 http://127.0.0.1:10000/devstoreaccount1,若返回 XML 格式的容器列表,说明服务正常
  • 检查启动命令是否正确,确保没有遗漏 --blobHost 127.0.0.1 之类的绑定参数,避免端口无法访问

内容的提问来源于stack exchange,提问作者Aryaman Maheshwari

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 00:33:30