skip to Main Content

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.

5

Answers


  1. Chosen as BEST ANSWER

    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.


  2. We’ve had reports of this being a problem on CentOS specifically with version 6.7 but it possibly affects the 7.x releases too.

    It appears that the wrong Python is getting called. This isn’t strictly a Cassandra issue but a problem with the Python on the machine. You can verify which Python gets run with:

    $ which python
    

    As a workaround, you should be able to run cqlsh using the system Python as follows:

    $ /usr/local/bin/python /usr/bin/cqlsh
    

    Cheers!

    Login or Signup to reply.
  3. Use pip3 to install or upgrade to the current six.

    Edit a copy of cqlsh. Change

    third_parties = ('futures-', 'six-', 'geomet-')
    

    to

    third_parties = ('futures-', 'geomet-')
    

    Not proud, but it worked.

    Login or Signup to reply.
  4. Used pip3 to install, and found this issue as well.

    For me, removing six dependencies from /usr/lib/python3/dist-packages was the only thing that worked.

    rm six-1.11.0.egg-info and rm -r six-1.11.0.egg-info

    I couldn’t uninstall it with pip3, so manual removal was the way to go, followed by a pip3 install six

    Once that was back in place, cqlsh ran without issue.

    Login or Signup to reply.
  5. The previous answers didn’t work for me, I had to delete the Cassandra included six package, and then cqlsh used the system-wide package.

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

    Maybe an older version of Cassandra installed, and a newer version of cqlsh?

    https://community.datastax.com/questions/12085/unable-to-connect-to-cqlsh.html

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search