我想跟隨下面的視頻關於寫路徑,當我使用提供的示例學生文件,我得到下面的錯誤....我真的新的cassandra,並試圖找出爲什麼excerise文件不工作....我提供了我得到的錯誤(ImportError:沒有名爲cassandra.cluster的模塊)以及.sh和.py文件...任何幫助是appriciated ...錯誤... ImportError:沒有模塊名爲cassandra.cluster
https://academy.datastax.com/courses/understanding-cassandra-write-path/understanding-data-files
[email protected]:~/student-files/write-path/exercise-1$ ccm list
*demo_1node
[email protected]:~/student-files/write-path/exercise-1$
[email protected]:~/student-files/write-path/exercise-1$ ccm status
Cluster: 'demo_1node'
---------------------
node1: UP
[email protected]:~/student-files/write-path/exercise-1$
[email protected]:~/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
[email protected]:~/student-files/write-path/exercise-1$
[email protected]:~/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
[email protected]:~/student-files/write-path/exercise-1$
[email protected]:~/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()
[email protected]:~/student-files/write-path/exercise-1$
您是否安裝了datastax python驅動程序? – Richard 2014-09-28 18:58:37
感謝richard,正如我剛纔提到的,我對這個真的很陌生......但是在安裝python驅動之後,它似乎能夠發出警告...... – 2014-09-29 13:45:59
cass @ cass:〜/ student-files/write-path/exercise- 1 $ ./write_data.sh 3000 /usr/local/lib/python2.7/dist-packages/cassandra/cqltypes.py:64:UserWarning:blist庫不可用,因此將使用普通集合設置集合值的blist.sortedset。您可以在此處找到blist庫:https://pypi.python.org/pypi/blist/ 「blist庫不可用,因此正常集合將會」完成25%「 - 插入750行。 完成50% - 插入1500行。 完成75% - 插入2250行。 完成100% - 插入3000行。 cass @ cass:〜/ student-files/write-path/exercise-1 $ – 2014-09-29 13:46:27