11

When importing datastax cassandra-driver(python) get the following error

Error

File "cassandra.py", line 1, in <module>
    from cassandra.cluster import Cluster
File "/home/vagrant/cassandra.py", line 1, in <module>
    from cassandra.cluster import Cluster
ImportError: No module named cluster

This is the code

from cassandra.cluster import Cluster
print dir(cassandra.cluster)
cluster = Cluster()
session = cluster.connect('userspace')
rows = session.execute('SELECT user_name, gender FROM users')
for user_row in rows:
    print user_row.user_name, user_row.gender
jereques
  • 113
  • 1
  • 1
  • 5

3 Answers3

20

Well, it looks like names conflict. Your script is cassandra.py and so it is the module for the driver. Try to rename your script (and don't forget to delete its .pyc) and try again

Mikhail Stepura
  • 3,374
  • 20
  • 16
  • 1
    Any file which matches a keyword (say select.py) will make it run that file instead of resolving the keyword. I was using a script named - select.py which resulted in similar error and when I renamed the script to something which could not match any of it, the issue got resolved. – Coder Aug 26 '16 at 05:04
1

Install CQL interactive terminal:

sudo pip install cqlsh
Cà phê đen
  • 1,883
  • 2
  • 21
  • 20
y durga prasad
  • 1,184
  • 8
  • 11
0

I tried this and it worked in my case: python -m pip install `

for example: python -m pip install cassandra-driver