【问题标题】:ModuleNotFoundError: No module named 'cassandra.cluster'; 'cassandra' is not a packageModuleNotFoundError:没有名为“cassandra.cluster”的模块; 'cassandra' 不是一个包
【发布时间】:2021-10-12 07:44:12
【问题描述】:

我试过pip install cassandra-driver 在 pycharm 终端内,管理员模式下的 conda 命令提示符,我升级/降级了 cassandra-driver 版本,重新启动 pycharm,创建了新的 env,仍然显示错误。

这是我的代码。

import cassandra
from cassandra.cluster import Cluster

我的错误按摩:

C:\Anaco3.8\envs\FlipScap\python.exe 
C:/Users/Rushikesh/Downloads/FlipkratScrappingProject/cassan2.py
Traceback (most recent call last):
File "C:/Users/Rushikesh/Downloads/FlipkratScrappingProject/cassan2.py", line 1, in <module>
import cassandra
File "C:\Users\Rushikesh\Downloads\FlipkratScrappingProject\cassandra.py", line 3, in <module>
from cassandra.cluster import Cluster
ModuleNotFoundError: No module named 'cassandra.cluster'; 'cassandra' is not a package

【问题讨论】:

  • 欢迎来到 SO;请注意,错误之后出现的任何代码都与问题无关(从未执行),并且不应包含在此处,因为它只会造成不必要的混乱(已删除)。

标签: python python-3.x cassandra modulenotfounderror


【解决方案1】:

错误提示没有安装Cassandra Python驱动。

如果您还没有安装,请尝试使用:

$ pip3 install cassandra-driver

通过运行检查安装是否成功:

$ python -c 'import cassandra; print cassandra.__version__'

如果安装正确,你应该得到类似“3.25.0”的东西。

【讨论】:

    【解决方案2】:

    我认为我们可以为此责怪我们亲爱的 DataStax,他们提到 Cluster with no camel-case 并导致了这个问题。

    首先确保你已经安装了包(pip3 install cassandra-driver),然后使用下面的代码。

    就这样用吧:

    from cassandra.cluster import Cluster
    cluster = Cluster(['172...', '172...','172...'])
    

    将所有“172...”替换为您的集群 IP 集。

    【讨论】:

    猜你喜欢
    • 2017-09-23
    • 1970-01-01
    • 2020-09-09
    • 2020-12-06
    • 2020-12-27
    • 2020-10-04
    • 2020-07-02
    • 2021-05-17
    • 2018-05-08
    相关资源
    最近更新 更多