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
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 ofsix
into the following path:then
cqlsh
try to force the python interpreter to import the library from this path by adding the following lines to the code.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:Then I try to install the last compatible version on
six
using this command:That's it! problem solved and now I'm using
cqlsh
without any problem. I hope it helps others.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:
As a workaround, you should be able to run
cqlsh
using the system Python as follows:Cheers!
Use
pip3
to install or upgrade to the currentsix
.Edit a copy of cqlsh. Change
to
Not proud, but it worked.
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
andrm -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.
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