pythoncassandracentoscqlsh

CQLSH ImportError: cannot import name ensure_str


I have installed Cassandra database on my CentOs system. after that, I tried to install the Cqlsh package using this command sudo yum install cqlsh and it has been installed successfully. but when I tried to run cqlsh from the terminal, the following error appears:

ImportError: cannot import name ensure_str

somewhere in the code, it tries to load a library named six that contains ensure_str. the error does not say that it can not find a module named six, the python interpreter can find the library but can not import it!
I have tried googling but none of the solutions worked for me.


Solution

  • after a few hours of googling and struggling with the code, finally, I find out the solution. and I'm going to share it with others.

    apparently, the problem is the new version of six (v=1.7.3) which is not compatible with my system. However, Cassandra copies the last version of six into the following path:

    /usr/share/cassandra/lib/six-1.7.3-py2.py3-none-any.zip

    then cqlsh try to force the python interpreter to import the library from this path by adding the following lines to the code.

    third_parties = ('futures-', 'six-', 'geomet-')
    
    for lib in third_parties:
        lib_zip = find_zip(lib)
        if lib_zip:
            sys.path.insert(0, lib_zip)
    

    no matter if you have another version of six installed on your system, it always tries to import the library from the Cassandra folder.

    So, I have just deleted these lines from cqlsh file using this command:

    vim /usr/bin/cqlsh
    

    Then I try to install the last compatible version on six using this command:

    yum install six
    

    That's it! problem solved and now I'm using cqlsh without any problem. I hope it helps others.