在 Windows 10 上使用 python 3 运行 cassandra cqlsh

blu*_*ndr 4 python cassandra cqlsh

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

当我运行命令时,我收到此错误:

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
Run Code Online (Sandbox Code Playgroud)

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

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')
Run Code Online (Sandbox Code Playgroud)

Cassandra 似乎运行得很好,我只需要一种方法来连接它。

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

我怎样才能让它工作?

Ale*_*Ott 6

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


小智 5

我有一个更好的解决方法来解决这个问题,我有同样的问题,因为我有 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>
Run Code Online (Sandbox Code Playgroud)