5

I'm trying to run the cassandra cqlsh command using python 3 on windows 10.

When I run the command I get this error:

cqlsh
  File "C:\Program Files\apache-cassandra-3.11.6\bin\\cqlsh.py", line 248
    CONFIG_FILE = os.path.join(HISTORY_DIR, 'cqlshrc')
    ^
SyntaxError: invalid syntax

This is where the line is that it's complaining about in the script:

if hasattr(options, 'cqlshrc'):
    CONFIG_FILE = options.cqlshrc
    if not os.path.exists(CONFIG_FILE):
        print('\nWarning: Specified cqlshrc location `%s` does not exist.  Using `%s` instead.\n' % (CONFIG_FILE, HISTORY_DIR)
        CONFIG_FILE = os.path.join(HISTORY_DIR, 'cqlshrc')

Cassandra seems to be running just fine, I just need a way to connect with it.

I'm on Python 3.8.3, and I would prefer not to downgrade to 2.7 if I can help it.

How can I get this working?

bluethundr
  • 1,005
  • 17
  • 68
  • 141

3 Answers3

6

Released version of cqlsh supports only Python 2.7, so it can't work on the Python 3.x.
Support for Python 3 will be only in the Cassandra 4, that hopefully will be released this year. See CASSANDRA-15659, CASSANDRA-10190, CASSANDRA-15573 for more details.

Alex Ott
  • 80,552
  • 8
  • 87
  • 132
4

I have a better workaround for this issue , I have same problem as I have python 3.8 . I user docker with CQL . Cassandra is hosted on my Linux box where python version is 3.8. I install cqlsh thru docker and connect cassandra via docker

[root@localmonitor ~]# python
Python 3.8.3 (default, Aug 31 2020, 16:03:14)
[GCC 8.3.1 20191121 (Red Hat 8.3.1-5)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
[2]+  Stopped                 /usr/bin/python3
 docker run -it  --rm cassandra cqlsh 192.168.1.117
Connected to Test Cluster at 192.168.1.117:9042.
[cqlsh 5.0.1 | Cassandra 3.11.9 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh>
1

As a working workaround you can install cassandra version 4.

It contains cqlsh.py file which works with python 3.8.x

The only one thing that I've done, - I've copied cqlsh.bat from cassandra version 3 to to cassandra version 4, because due to some reasons it is absent. (but thats only for windows users like me)

So, after it you just run your cassandra and then run cqlsh client from cassandra-version-4

alexadr
  • 113
  • 2
  • 8
  • I have trying this, but v4 cqlsh.py has a cqlshlib import, and from what I can tell, the pypi.org still modules are python 2.7. – Brad Schoening May 25 '21 at 14:49