Cassandra 3.11.3 and cqlsh not support python 3.6 and 3.7?

Viewed 3291

I have installed Python 3.6 or 3.7 with Cassandra 3.11.3.
But it does not supporte cqlsh, it only supports the Python 2.7 version.
This is the error message:

\apache-cassandra-3.11.3\bin\\cqlsh.py", line 146  
    except ImportError, e:  
                      ^  
SyntaxError: invalid syntax  

What may be the problem?

4 Answers

Change

except a, b:

to

except a as b:

Add parens to prints

Change: except ImportError, e: To: except ImportError as ex: or
except ImportError:

Cqlsh is written in Py2.7, so it'll not build on py3 wrapper env. Even if you change the exception line, it'll not compile the. For example, take this line:

File "/home/usr/.local/bin/cqlsh", line 212
    print '\nWarning: Specified cqlshrc location `%s` does not exist.  Using `%s` instead.\n' % (CONFIG_FILE, HISTORY_DIR)
                                                                                            ^
SyntaxError: invalid syntax

Optional solutions:

  • Downgrade your python version using sudo-alternatives (check versions with update-alternatives --list python)
  • Correct the entire file (not viable)
  • Connect throug datastax or similar driver and query.

If you have the both version, set the Python2.7 as the main one. You can check the principal version using the command python -V. Then change using this command sudo ln -sf /usr/bin/python3.6 /usr/bin/python (use your path python 3x and 2x). Check if it was ok using python -V. Call the $cqlsh again.

Ps.: If necessary check the cqlsh file, if the header is correct. If it is #!/usr/bin/python3 fix to #!/usr/bin/python. You can use $find / -name cqlshto find the files.

Related