我正在尝试按照以下关于写路径的视频,当我使用提供的示例学生文件时,我得到以下错误....我是cassandra的新手,并试图找出为什么excerise文件不工作....我提供了我得到的错误(ImportError:没有名为cassandra.cluster的模块)以及.sh和.py文件...任何帮助都是适用的...
https://academy.datastax.com/courses/understanding-cassandra-write-path/understanding-data-files
cass@cass:~/student-files/write-path/exercise-1$ ccm list
*demo_1node
cass@cass:~/student-files/write-path/exercise-1$
cass@cass:~/student-files/write-path/exercise-1$ ccm status
Cluster: 'demo_1node'
---------------------
node1: UP
cass@cass:~/student-files/write-path/exercise-1$
cass@cass:~/student-files/write-path/exercise-1$ ./write_data.sh 300000
Traceback (most recent call last):
File "./write_data.py", line 5, in <module>
from cassandra.cluster import Cluster
ImportError: No module named cassandra.cluster
cass@cass:~/student-files/write-path/exercise-1$
cass@cass:~/student-files/write-path/exercise-1$ cat write_data.sh
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: write_data.sh <number of keys>"
exit 0
fi
if [ `ccm status | grep "node1: UP" | wc -l` -ne 1 ]; then
echo "Cassandra cluster not up"
exit 0
fi
./write_data.py $1
cass@cass:~/student-files/write-path/exercise-1$
cass@cass:~/student-files/write-path/exercise-1$ cat write_data.py
#!/usr/bin/python
# This Python script will insert a number of keys into
# musicdb.user
from cassandra.cluster import Cluster
from random import randint
from sets import Set
from uuid import uuid4
import os,sys,time,binascii
if len(sys.argv) < 2:
print "Usage: python.py <number of keys>"
sys.exit()
cluster = Cluster(['127.0.0.1'])
session = cluster.connect()
insert_row_prepare = session.prepare("INSERT INTO musicdb.user (id,preferences) VALUES(?,?)")
quarter=int(int(sys.argv[1])/4)
half=int(int(sys.argv[1])/2)
three_quarter=int(int(sys.argv[1])/4)+int(int(sys.argv[1])/2)
for x in range(0,int(sys.argv[1])):
id = uuid4()
set = Set([binascii.b2a_hex(os.urandom(100)),binascii.b2a_hex(os.urandom(100)),binascii.b2a_hex(os.urandom(100)),
binascii.b2a_hex(os.urandom(100)),binascii.b2a_hex(os.urandom(100)),binascii.b2a_hex(os.urandom(100)),
binascii.b2a_hex(os.urandom(100)),binascii.b2a_hex(os.urandom(100)),binascii.b2a_hex(os.urandom(100)),
binascii.b2a_hex(os.urandom(100)),binascii.b2a_hex(os.urandom(100)),binascii.b2a_hex(os.urandom(100))])
insert_row_bind = insert_row_prepare.bind([id,set])
session.execute(insert_row_bind)
if (x+1) == int(sys.argv[1]):
print "100% completed - " + str(x+1) + " rows inserted."
elif (x+1) == quarter:
print "25% completed - " + str(x+1) + " rows inserted."
elif (x+1) == half:
print "50% completed - " + str(x+1) + " rows inserted."
elif (x+1) == three_quarter:
print "75% completed - " + str(x+1) + " rows inserted."
time.sleep(1)
cluster.shutdown()
cass@cass:~/student-files/write-path/exercise-1$
答案 0 :(得分:2)
安装cassandra驱动程序:
pip install cassandra-driver
答案 1 :(得分:0)
我也遇到同样的问题。当我看到答案时,我意识到我可能已经安装了适用于Python 2的驱动程序。我尝试了以下操作,现在可以使用了:
pip3 install cassandra-driver
由于Python 2和Python 3如此不兼容,因此python开发人员确实对noobs造成了困难。
答案 2 :(得分:-3)
您需要安装python驱动程序。