You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac M1系统运行cqlsh报错:Python模块're'无'sre_parse'属性

Mac M1系统cqlsh启动报错(AttributeError: module 're' has no attribute 'sre_parse')解决方法

执行bin/cqlsh时触发如下报错:

% bin/cqlsh
Traceback (most recent call last):
  File "/Users/avinashkasukurthi/devtools/apache-cassandra-4.0.7/bin/cqlsh.py", line 159, in <module>
    from cqlshlib import cql3handling, cqlhandling, pylexotron, sslhandling, cqlshhandling
  File "/Users/avinashkasukurthi/devtools/apache-cassandra-4.0.7/bin/../pylib/cqlshlib/cql3handling.py", line 19, in <module>
    from cqlshlib.cqlhandling import CqlParsingRuleSet, Hint
  File "/Users/avinashkasukurthi/devtools/apache-cassandra-4.0.7/bin/../pylib/cqlshlib/cqlhandling.py", line 23, in <module>
    from cqlshlib import pylexotron, util
  File "/Users/avinashkasukurthi/devtools/apache-cassandra-4.0.7/bin/../pylib/cqlshlib/pylexotron.py", line 342, in <module>
    class ParsingRuleSet:
  File "/Users/avinashkasukurthi/devtools/apache-cassandra-4.0.7/bin/../pylib/cqlshlib/pylexotron.py", line 343, in ParsingRuleSet
    RuleSpecScanner = SaferScanner([
                      ^^^^^^^^^^^^^^
  File "/Users/avinashkasukurthi/devtools/apache-cassandra-4.0.7/bin/../pylib/cqlshlib/saferscanner.py", line 91, in __init__
    s = re.sre_parse.State()
        ^^^^^^^^^^^^
AttributeError: module 're' has no attribute 'sre_parse'

核心问题是Python高版本中re模块不再暴露sre_parse属性,导致cqlsh依赖的代码执行失败。

解决方法

方法1:修改cqlsh源码文件

找到Cassandra安装路径下的pylib/cqlshlib/saferscanner.py,定位到第91行:

s = re.sre_parse.State()

替换为:

import _sre
s = _sre.State()

保存后重新执行bin/cqlsh即可正常启动。

方法2:指定Python 2.7运行cqlsh

Cassandra 4.0.x的cqlsh兼容Python 2.7,直接指定解释器运行:

python2.7 bin/cqlsh

若系统没有Python 2.7,通过Homebrew安装:

brew install python@2

方法3:升级Cassandra版本

Cassandra 4.1及以上版本已修复该Python兼容问题,升级到对应版本后即可直接使用cqlsh。

内容的提问来源于stack exchange,提问作者Avinash Kasukurthi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 18:35:21