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

Databricks中使用with open读取DBFS挂载文件失败,如何解决?

Databricks中Python原生读取DBFS文件失败问题

问题详情

尝试用Python原生with open读取DBFS挂载路径下的JSON文件,代码如下:

import json
my_json = ''
with open('/dbfs/mnt/my_mount/my_json.json', 'r') as fp:
    my_json = json.load(fp)

执行后抛出错误:

FileNotFoundError: [Errno 2] No such file or directory: '/dbfs/mnt/my_mount/my_json.json'

但使用Spark DataFrame读取同一文件完全正常,代码及验证:

df = spark.read.text('/dbfs/mnt/my_mount/my_json.json', wholetext=True)
df.show()  # 可正常显示文件内容

环境信息

使用的Databricks Runtime版本:
Databricks Runtime 11.3 LTS (includes Apache Spark 3.3.0, Scala 2.12)

求助需求

如何通过Python原生的with open方法读取该文件?

内容的提问来源于stack exchange,提问作者Sarath Subramanian

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 07:10:44