通过运行命令安装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
看到没有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
?
注意:我正在关注this文档。
答案 0 :(得分:1)
您是否尝试运行这些演示(来自那些文档)?
“如果成功,您应该能够构建和安装扩展(仅使用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
答案 1 :(得分:0)
$ echo 'import cassandra.cluster' > cassandra.py && python3 cassandra.py
Traceback (most recent call last):
File "./cassandra.py", line 3, in <module>
import cassandra
File "/home/xxx/cassandra.py", line 4, in <module>
import cassandra.cluster
ModuleNotFoundError: No module named 'cassandra.cluster'; 'cassandra' is not a package
使用不同的文件名,错误消失:
echo 'import cassandra.cluster' > tmp.py && python3 cassandra.py
所以,对我来说,错误是我自己的程序覆盖了包。哦