无法将文件从DBFS复制到Databricks中的本地桌面

时间:2019-11-14 19:31:29

标签: python 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

2 个答案:

答案 0 :(得分:0)

您需要使用Databricks CLI来完成此任务。

在本地计算机上安装CLI,然后运行databricks configure进行身份验证。使用在用户设置下生成的访问令牌作为密码。

一旦已安装CLI并将其配置到工作区,就可以像这样在DBFS之间复制文件:

databricks fs cp dbfs:/path_to_file/my_file /path_to_local_file/my_file

您也可以使用速记

dbfs cp dbfs:/path_to_file /path_to_local_file

答案 1 :(得分:0)

要将文件从DBFS下载到本地计算机,您可以按照以下步骤操作。

使用cmd安装和配置Azure Databricks CLI的步骤:

第1步:安装Python,如果您使用的是Python 2,则需要Python 2.7.9及更高版本;如果您使用的是Python 3,则需要Python 3.6及更高版本。

第二步::使用适合您的Python安装的pip版本运行pip install databricks-cli。如果您使用的是Python 3,请运行pip3 install databricks-cli

第3步::设置身份验证=>要验证和访问Databricks REST API,请使用个人访问令牌。令牌类似于密码。您应该小心对待他们。令牌已过期,可以撤销。

  • 单击用户配置文件图标右上角的用户配置文件 您的Azure Databricks工作区。

  • 单击用户设置。

  • 转到“访问令牌”标签。

enter image description here

  • 单击“生成新令牌”按钮。
  • (可选)输入说明(评论)和有效期。

enter image description here

  • 点击生成按钮。
  • 确保“复制”所生成的令牌并将其存储在安全的位置。

第4步::复制创建先前步骤的数据块主机"https://centralus.azuredatabricks.net/"的URL和令牌。

第5步:在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。

enter image description here

参考: Databricks CLI

您可以使用databricks cli如下将文件从databricks文件系统下载到本地计算机;

dbfs cp dbfs:/myfolder/BRK4024.pptx A:DataSet\

示例:由于我在dbfs上的myfolder中有一个示例BRK4024.pptx文件,因此我正在使用databricks cli命令复制到本地计算机文件夹名称(A:Dataset)

enter image description here

希望这会有所帮助。


如果这回答了您的查询,请同时单击“标记为答案”和“上投票”。而且,如果您还有其他疑问,请告诉我们。