Python 在 Databricks 中导入 simple_salesforce 给出:没有名为 cryptography.hazmat.primitives.asymmetric.ed25519 的模块

Python import simple_salesforce in Databricks gives: No module named cryptography.hazmat.primitives.asymmetric.ed25519

我正在尝试使用 Azure Databricks 启动 Python 导入库的脚本:“simple_salesforce”

我已经安装了如下图所示的库,请注意,在安装库时,名称应该是“simple-salesforce”,而在导入时,名称应该是“simple_salesforce”(只是提一下我没记错名字): Installation of the library

如下图所示,库安装成功: simple-salesforce installed

当尝试将其导入我的工作区时,使用:

import simple_salesforce

我收到以下错误(请参阅下面的错误图片):

ImportError: No module named 'cryptography.hazmat.primitives.asymmetric.ed25519'

Error

我已经尝试使用与安装其他库相同的方法安装“cryptography”库(见下图),但我仍然遇到相同的错误: cryptography

有没有我漏掉的步骤?

此致,

您没有安装库“cryptography”。您很可能使用的是 5.5 LTS 或更低版本的 Databricks 运行时版本,只有一名工人。

问题是您有一个带 Python3 的 Databricks 集群,笔记本是 运行 在 Python2 内核上。

方法一

检查是否有 python 3:

%sh
python3 --version

然后安装pip3:

%sh
sudo apt install python3-pip

之后你可以安装“cryptography”

方法二

我强烈推荐这种方法,它包括使用 7.4 Databricks Runtime 版本和至少 2 个工人,然后你将有 python3 和默认安装的库“cryptography”。

您只需要从库部分手动安装 simple-salesforce,并且:

import simple_salesforce