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

2024-04-28 14:33:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在Windows10上使用Python3运行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')

卡桑德拉似乎运行得很好,我只是需要一种方法来连接它

我使用的是Python3.8.3,如果可以的话,我不希望降级到2.7

我怎样才能让它工作


Tags: path命令configifosdirnothistory
3条回答

发布的cqlsh版本只支持Python2.7,因此无法在Python3.x上工作。
对Python3的支持只会出现在Cassandra4中,有望在今年发布。有关详细信息,请参见CASSANDRA-15659CASSANDRA-10190CASSANDRA-15573

对于这个问题,我有一个更好的解决方法,我的问题与Python3.8相同。 我使用CQL访问用户docker。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

它包含与python 3.8.x一起使用的cqlsh.py文件

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

所以,在它之后,您只需运行您的cassandra,然后从cassandra-version-4运行cqlsh客户机

相关问题 更多 >