22

I am new to cassandra ! Have downloaded the apacahe cassandra 2.1.2 package and initialy was able to connect to cqlsh but then after installing CCM i am unable to connect , will get the following error

Traceback (most recent call last):
File "bin/cqlsh", line 124, in <module>
from cqlshlib import cql3handling, cqlhandling, pylexotron,sslhandling, copy
ImportError: No module named cqlshlib

Thanks in advance !

Shreesha N
  • 892
  • 2
  • 8
  • 20
  • Can you give the command line you used for creating and starting your CCM cluster please. – mikea Feb 04 '16 at 15:15
  • In addition, how are you executing cqlsh?, after you create a cluster with ccm are you running it stand alone or via ccm. Does cqlsh work when run through via ccm? You should be able to connect using ccm and cqlsh by running the "ccm cqlsh" – Greg Bestland Feb 04 '16 at 17:19
  • I just downloaded a new cassandra package from apache and started with that ! worked al fine ! thanks guys – Shreesha N Feb 05 '16 at 07:14

9 Answers9

21

Spent a couple of days, scouring the net moving renaming copying packages .

Easiest workaround for this error that worked :

pip install cqlsh

Saleem Ahmed
  • 2,719
  • 2
  • 18
  • 31
13

You could export PYTHONPATH, to include site package folder where cqlshlib exists

First find the path where cqlshlib exists

find /usr/lib/ -name cqlshlib

Export the path using below variable name

export PYTHONPATH=/usr/lib/python2.7/site-packages/
faizan
  • 680
  • 1
  • 6
  • 15
5

I have tried their ways, but failed. And I think cqlsh just cannot find the exact path to cqlshlib.so;

I solved it this way:

  • Centos6.7 ,
  • datastax3.9,
  • my cqlshlib path:/usr/local/lib/python2.7/site-packages/

    vim /usr/bin/cqlsh.py

and add the path of cqlshlib after import sys, the file looks like:

...
import sys
...
from uuid import UUID
sys.path.append("/usr/local/lib/python2.7/site-packages") #add this sentence`

Then I execute cqlsh, it works.

J. Chomel
  • 8,193
  • 15
  • 41
  • 69
David
  • 101
  • 1
  • 6
3

If you're in the cassandra directory, run:

bin/cqlsh

If you check the cqlsh you're running with which cqlsh i suspect you're hitting the ccm one and missing something in your path.

Jon Haddad
  • 766
  • 6
  • 17
2

Just start cqlsh with root,

  sudo cqlsh <ipaddress>
Ashok v
  • 77
  • 1
  • 8
2

The other answers correctly diagnose the problem. You need to find the correct cqlshlib. I had installed cassandra with apt get to Ubuntu, so the correct path for me was /usr/local/apache-cassandra-3.11.3/pylib

I had also messed things up by previously doing pip install cqlsh This is NOT supported by the apache team!

Like another answer here, I hacked the cqlsh.py file in /usr/bin

My successful hack was to replace the commented out line with the line below it.

#cqlshlibdir = os.path.join(CASSANDRA_PATH, 'pylib')
cqlshlibdir = "/usr/local/apache-cassandra-3.11.3/pylib"
Jake
  • 4,322
  • 6
  • 39
  • 83
1

I have spent nearly 1 day to solve this problem. The reason is that there is a mismatch between /usr/lib/python2.7/site-packages/ and /usr/local/lib/python2.7/site-packages/ (for my specific folder tree).

The command to use is as the following:

mv /usr/lib/python2.7/site-packages/* /usr/local/lib/python2.7/site-packages/
rmdir /usr/lib/python2.7/site-packages
ln -s /usr/local/lib/python2.7/site-packages /usr/lib/python2.7/site-packages

I guess you will find 2 /site-packages/ also.

Just for reference for others.

Ying LEE
  • 93
  • 5
0

Workaround:

I assume that you have already installed Cassandra and cqlshlib has been installed in /usr/lib/python2.7/site-packages/

`ln -s /usr/lib/python2.7/site-packages/cqlshlib /usr/local/lib/python2.7/site-packages/cqlshlib` 

(replace /usr/lib/python2.7/site-packages with your python directory).

More Detail:

One possibility is that your default python is not in /usr/bin/. Say it has been installed in /usr/local/bin/. However, Cassandra seems to install cqlshlib in /usr/lib/python2.7/site-packages for some reason. As a result, the default python cannot find cqlshlib package when you run cqlsh command.

amn
  • 1
  • 2
0

As Cassandra supports python2 and you are on python3 and don't wanna mix both follow the below trick worked for me.

  1. Install python2 but don't add it to the environmental path variable
  2. navigate to the bin folder and start the Cassandra server .\cassandra -f
  3. open another terminal and create virtual env in Cassandra home directory using below command virtualenv -p C:\Python27\python.exe .\venv
  4. activate the virtual env with cmd .\venv\Scripts\activate.ps1
  5. start the cqlsh using the cmd .\cqlsh.bat in virtual env