cassandra-driver: ImportError: No module named queue

cassandra-driver: ImportError: No module named queue

我正在 OSX 10.11 上使用 pip 安装 cassandra-driver。 直接从 pip 出来,cassandra-driver 给出了这个错误:

traceback (most recent call last):   File "syncS3ToCassandra.py", line 19, in <module>
from cassandra.cluster import Cluster   File "cassandra/cluster.py", line 48, in init cassandra.cluster (cassandra/cluster.c:74747)   
File "cassandra/connection.py", line 38, in init cassandra.connection (cassandra/connection.c:28007) 
ImportError: No module named queue

我没有尝试从源代码构建 cassandra-driver,但 pip 是推荐的方法。这是我的代码:

from cassandra.cluster import Cluster
from cassandra.policies import DCAwareRoundRobinPolicy

cluster = Cluster()
session = cluster.connect('foo')

从源代码来看,您需要安装 six 包,并且它应该有一个包含模块 moves 的子包 moves =15=]queue.py:

38    from six.moves.queue import Queue, Empty

你能试试重新安装六个吗?

  1. pip 卸载六
  2. pip 安装六

由于 cassandra-driver(版本 3.4.1)仅作为 .tar.gz 包提供,您必须从源代码重新编译它。这就是 pip 所做的。

我在 OSX 10.11.5 上成功安装(编译至少花了一分钟)。

我试试这个:

$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from cassandra.cluster import Cluster
>>> from cassandra.policies import DCAwareRoundRobinPolicy
>>> cluster = Cluster()
>>> session = cluster.connect('foo')
Traceback (most recent call last):
  ...
cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers', {'127.0.0.1': error(61, "Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused")})

最后一个错误是正常的,因为我没有服务器

编辑:安装在 Python 3.5

我在 OSX 10.11.5

Python 3.5.1 中成功安装并测试了这个驱动程序(尽我所能)
$ python
Python 3.5.1 (v3.5.1:37a07cee5969, Dec  5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from cassandra.cluster import Cluster
>>> from cassandra.policies import DCAwareRoundRobinPolicy
>>> cluster = Cluster()
>>> session = cluster.connect('foo')
Traceback (most recent call last):
...
cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers'[..])

我使用基本前缀 '/Library/Frameworks/Python.framework/Versions/3.5'.

创建了一个 virtualenv

我通过更新我的 ~/.profile 解决了这个问题:

export PATH=/usr/local/bin:/usr/local/sbin:$PATH

并安装 python-2.7.11

$ brew install python

然后重新启动我的 shell。

我的 mbp 也遇到了这个问题。并且还有一些其他问题无法卸载六。我使用 easy_install 将版本从 1.4.1 更新到 1.10.0 来修复它。

$sudo easy_install -U six

希望对您有所帮助