无法将文件从 DBFS 复制到 Databricks 中的本地桌面
Not able to copy file from DBFS to local desktop in Databricks
我想将我的文件从 dbfs 保存或复制到我的桌面(本地)。我使用此命令但出现错误:
dbutils.fs.cp('/dbfs/username/test.txt', 'C:\Users\username\Desktop')
Error: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
当我为我的案例查找 dbutils.fs.help() 时,我遵循了说明:
dbutils.fs provides utilities for working with FileSystems. Most methods in this package can take either a DBFS path (e.g., "/foo" or "dbfs:/foo"), or another FileSystem URI. For more info about a method, use dbutils.fs.help("methodName"). In notebooks, you can also use the %fs shorthand to access DBFS. The %fs shorthand maps straightforwardly onto dbutils calls. For example, "%fs head --maxBytes=10000 /file/path" translates into "dbutils.fs.head("/file/path", maxBytes = 10000)".
fsutils
cp(from: String, to: String, recurse: boolean = false): boolean -> Copies a file or directory, possibly across FileSystems
您需要使用 Databricks CLI 来完成此任务。
在您的本地计算机上安装 CLI 并 运行 databricks configure
进行身份验证。使用在用户设置下生成的访问令牌作为密码。
安装 CLI 并将其配置到工作区后,您可以像这样将文件复制到 DBFS 或从中复制文件:
databricks fs cp dbfs:/path_to_file/my_file /path_to_local_file/my_file
您也可以使用 shorthand
dbfs cp dbfs:/path_to_file /path_to_local_file
要从 DBFS 下载文件到本地机器,您可以按照以下步骤操作。
使用 cmd 安装和配置 Azure Databricks CLI 的步骤:
第 1 步: 安装 Python,如果您使用 Python 2,则需要 Python 2.7.9 及更高版本或 Python 3.6 及更高版本,如果您使用 Python 3.
第 2 步: 运行 pip install databricks-cli
使用适合您 Python 安装的 pip 版本。如果您使用 Python 3, 运行 pip3 install databricks-cli
.
第 3 步: 设置身份验证 => 要对 Databricks REST API 进行身份验证和访问,您需要使用个人访问令牌。令牌类似于密码;你应该小心对待他们。令牌过期并且可以被撤销。
点击右上角的用户个人资料图标用户个人资料
你的 Azure Databricks 工作区。
单击“用户设置”。
转到“访问令牌”选项卡。
- 单击“生成新令牌”按钮。
- 可选择输入描述(评论)和有效期。
- 单击“生成”按钮。
- 确保 "Copy" 生成的令牌并存储在安全位置。
Step4:复制databricks主机URL"https://centralus.azuredatabricks.net/"
和之前创建的token。
Step5:在cmd中运行"dbfs configure --token"如下图:
dbfs configure --token
Databricks Host (should begin with https://): https://centralus.azuredatabricks.net
Token: dapi72026dsfsdfsh987hjfiu431
第 6 步: 使用 CMD 成功配置 Databricks CLI。
要验证尝试 运行 "databricks fs ls",检查您是否能够看到 DBFS。
参考: Databricks CLI
您可以使用 databricks cli 将文件从 databricks 文件系统下载到本地计算机,如下所示;
dbfs cp dbfs:/myfolder/BRK4024.pptx A:DataSet\
示例: 因为我在 dbfs 上的 myfolder 中有一个示例 BRK4024.pptx 文件,所以我正在使用 databricks cli 命令复制到本地计算机文件夹名称(A:数据集)
希望对您有所帮助。
如果这回答了您的问题,请点击“标记为答案”并点击 "Up-Vote"。而且,如果您有任何进一步的疑问,请告诉我们。
我想将我的文件从 dbfs 保存或复制到我的桌面(本地)。我使用此命令但出现错误:
dbutils.fs.cp('/dbfs/username/test.txt', 'C:\Users\username\Desktop')
Error: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
当我为我的案例查找 dbutils.fs.help() 时,我遵循了说明:
dbutils.fs provides utilities for working with FileSystems. Most methods in this package can take either a DBFS path (e.g., "/foo" or "dbfs:/foo"), or another FileSystem URI. For more info about a method, use dbutils.fs.help("methodName"). In notebooks, you can also use the %fs shorthand to access DBFS. The %fs shorthand maps straightforwardly onto dbutils calls. For example, "%fs head --maxBytes=10000 /file/path" translates into "dbutils.fs.head("/file/path", maxBytes = 10000)".
fsutils
cp(from: String, to: String, recurse: boolean = false): boolean -> Copies a file or directory, possibly across FileSystems
您需要使用 Databricks CLI 来完成此任务。
在您的本地计算机上安装 CLI 并 运行 databricks configure
进行身份验证。使用在用户设置下生成的访问令牌作为密码。
安装 CLI 并将其配置到工作区后,您可以像这样将文件复制到 DBFS 或从中复制文件:
databricks fs cp dbfs:/path_to_file/my_file /path_to_local_file/my_file
您也可以使用 shorthand
dbfs cp dbfs:/path_to_file /path_to_local_file
要从 DBFS 下载文件到本地机器,您可以按照以下步骤操作。
使用 cmd 安装和配置 Azure Databricks CLI 的步骤:
第 1 步: 安装 Python,如果您使用 Python 2,则需要 Python 2.7.9 及更高版本或 Python 3.6 及更高版本,如果您使用 Python 3.
第 2 步: 运行 pip install databricks-cli
使用适合您 Python 安装的 pip 版本。如果您使用 Python 3, 运行 pip3 install databricks-cli
.
第 3 步: 设置身份验证 => 要对 Databricks REST API 进行身份验证和访问,您需要使用个人访问令牌。令牌类似于密码;你应该小心对待他们。令牌过期并且可以被撤销。
点击右上角的用户个人资料图标用户个人资料 你的 Azure Databricks 工作区。
单击“用户设置”。
转到“访问令牌”选项卡。
- 单击“生成新令牌”按钮。
- 可选择输入描述(评论)和有效期。
- 单击“生成”按钮。
- 确保 "Copy" 生成的令牌并存储在安全位置。
Step4:复制databricks主机URL"https://centralus.azuredatabricks.net/"
和之前创建的token。
Step5:在cmd中运行"dbfs configure --token"如下图:
dbfs configure --token
Databricks Host (should begin with https://): https://centralus.azuredatabricks.net
Token: dapi72026dsfsdfsh987hjfiu431
第 6 步: 使用 CMD 成功配置 Databricks CLI。
要验证尝试 运行 "databricks fs ls",检查您是否能够看到 DBFS。
参考: Databricks CLI
您可以使用 databricks cli 将文件从 databricks 文件系统下载到本地计算机,如下所示;
dbfs cp dbfs:/myfolder/BRK4024.pptx A:DataSet\
示例: 因为我在 dbfs 上的 myfolder 中有一个示例 BRK4024.pptx 文件,所以我正在使用 databricks cli 命令复制到本地计算机文件夹名称(A:数据集)
希望对您有所帮助。
如果这回答了您的问题,请点击“标记为答案”并点击 "Up-Vote"。而且,如果您有任何进一步的疑问,请告诉我们。