首页 > 解决方案 > ModuleNotFoundError:没有名为“cassandra”的模块

问题描述

通过运行命令安装 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

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

File "<stdin>", line 1
    import cassandra-driver
                    ^
SyntaxError: invalid syntax

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

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

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

我的操作系统是 MacOS

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

标签: python-3.xcassandrapip

解决方案


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

“如果成功,您应该能够构建和安装扩展(只需使用 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()

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

我指的文档


推荐阅读