运行 cassandra cqlsh with python 3 on windows 10

Run cassandra cqlsh with python 3 on windows 10

我正在尝试 运行 在 windows 10 上使用 python 3 的 cassandra cqlsh 命令。

当我 运行 命令时我得到这个错误:

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

这是它在脚本中抱怨的地方:

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 似乎 运行ning 就好了,我只是需要一种方法来连接它。

我正在使用 Python 3.8.3,如果可以的话,我不想降级到 2.7。

我怎样才能让它工作?

cqlsh 的发布版本仅支持 Python 2.7,因此无法在 Python 3.x.
上运行 对 Python 3 的支持将仅出现在 Cassandra 4 中,有望在今年发布。有关详细信息,请参阅 CASSANDRA-15659, CASSANDRA-10190, CASSANDRA-15573

对于这个问题我有更好的解决方法,我遇到的问题与 python 3.8 相同。 我使用 docker 和 CQL 。 Cassandra 托管在我的 Linux 盒子上,其中 python 版本是 3.8。 我通过 docker 安装 cqlsh 并通过 docker

连接 cassandra
[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>

作为解决方法,您可以安装 cassandra 版本 4。

它包含 cqlsh.pypython 一起使用的文件 3.8.x

我做过的唯一一件事,- 我已经将 cqlsh.bat 从 cassandra 版本 3 复制到 cassandra 版本 4,因为由于某些原因它不存在。 (但这仅适用于 windows 像我这样的用户)

所以,在它之后你只是 运行 你的 cassandra 然后 运行 来自 cassandra-version-4

的 cqlsh 客户端