ModuleNotFoundError:没有名为“cassandra”的模块

avi*_*jay 5 pip cassandra python-3.x

通过运行命令安装 cassandra 驱动程序后: ,当我尝试通过运行行导入模块时sudo pip3 install cassandra-driver收到错误。ModuleNotFoundError: No module named 'cassandra'cassandra

pip3然后我尝试通过运行以下命令查看所有模块的安装内容pip3 freeze

astroid==2.1.0
cassandra-driver==3.16.0
isort==4.3.4
lazy-object-proxy==1.3.1
mccabe==0.6.1
pylint==2.2.2
six==1.12.0
wrapt==1.10.11
Run Code Online (Sandbox Code Playgroud)

看到 no cassandra,我尝试导入可见模块:cassandra-driver然后出现错误:

File "<stdin>", line 1
    import cassandra-driver
                    ^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

另外,当我用此更正连字符问题时: __import__("cassandra-driver"),我收到错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cassandra-driver'
Run Code Online (Sandbox Code Playgroud)

我的which python3是:/usr/local/bin/python3我的which pip3是:/usr/local/bin/pip3

我的操作系统是MacOS

如何安装cassandra?注意:我正在关注文档。

小智 2

您是否尝试运行这些演示(来自那些文档)?

“如果成功,您应该能够构建并安装扩展(只需使用 setup.py build 或 setup.py install),然后通过执行以下操作来使用 libev 事件循环:”

>>> from cassandra.io.libevreactor import LibevConnection
>>> from cassandra.cluster import Cluster

>>> cluster = Cluster()
>>> cluster.connection_class = LibevConnection
>>> session = cluster.connect()
Run Code Online (Sandbox Code Playgroud)

有可能实际模块的名称不同,例如,有另一个名为 Pillow 的外部包,但您使用名称“PIL”导入它。在他们正在导入的文档中from cassandra.cluster

我引用的文档