psutil库在databricks上的安装问题

我在我的databricks群集上使用了psutil库,该库在过去几周内运行良好。今天当我启动集群时,该特定的库无法安装。我注意到网站上有更新的psutil版本。

当前我的python脚本失败,并显示'No module psutil'

尝试使用pip install安装psutil的先前版本,但我的代码仍然失败,并出现相同的错误。

是否有psutil替代品,或者有将其安装在数据砖中的方法

deaddao 回答:psutil库在databricks上的安装问题

众所周知,有两种方法可以在Azure Databricks群集中安装Python程序包,如下所示。

  1. 如下图所示,移至群集的Libraries选项卡,然后单击Install New按钮以键入要安装的软件包名称,然后等待成功安装

    enter image description here

    enter image description here

  2. 打开一个笔记本,按如下所示键入shell命令以通过pip安装Python软件包。注意:在此处,要在databricks集群的当前环境中安装而不是在Linux的系统环境中安装,必须使用/databricks/python/bin/pip,而不仅仅是pip

    %sh
    /databricks/python/bin/pip install psutil
    

    enter image description here

最后,我运行下面的代码,它适用于上面的两种方式。

import psutil
for proc in psutil.process_iter(attrs=['pid','name']):
  print(proc.info)

psutil.pid_exists(<a pid number in the printed list above>)

enter image description here

,

除了@Peter响应外,您还可以使用“库实用程序”来安装Python库。

库实用程序允许您安装Python库并创建范围为笔记本会话的环境。这些库在驱动程序和执行程序上均可用,因此您可以在UDF中引用它们。这将启用:

  • 要在笔记本中组织的笔记本的库依赖性 笔记本本身。
  • 具有不同库依赖关系的笔记本用户 共享群集而不会受到干扰。

enter image description here

示例:要使用库实用程序安装“ psutil ”库,

dbutils.library.installPyPI("psutil")

enter image description here

**参考:** Databricks - library utilities

希望这会有所帮助。

本文链接:https://www.f2er.com/3155327.html

大家都在问