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

CentOS7运行cqlsh报错:Python Cassandra driver未安装/Zlib不可用求助

Fixing cqlsh "Python Cassandra driver not installed" & "zlib not available" Errors

Hey there, let's troubleshoot this cqlsh issue step by step. Based on your environment details (CentOS 7, Cassandra 3.6.0, Python 2.7.6), here are targeted fixes to resolve the errors you're seeing:

1. Verify Python Environment Consistency

The error points to /usr/local/bin/python as the Python path being used, but this might not be the same environment where you installed the Cassandra driver or zlib dependencies. First, check if this Python instance actually has access to both:

/usr/local/bin/python -c "import cassandra; import zlib; print('All dependencies loaded successfully!')"

If this command throws an error, it confirms the issue is isolated to this specific Python installation.

2. Fix the "zlib not available" Error

This usually happens if zlib wasn't included when compiling your /usr/local/bin/python instance, or the system-level zlib dev package is missing. Here's how to fix it:

  • First, install the system zlib development libraries:
    sudo yum install zlib-devel -y
    
  • If you compiled Python 2.7.6 manually, recompile it with zlib support:
    1. Grab the Python 2.7.6 source code, extract it, and navigate to the source directory
    2. Run the configure command with zlib enabled:
      ./configure --prefix=/usr/local --with-zlib
      
    3. Recompile and install:
      make && sudo make install
      
  • Verify zlib is now available:
    /usr/local/bin/python -c "import zlib; print('zlib version: {}'.format(zlib.ZLIB_VERSION))"
    

3. Install Cassandra Driver to the Correct Python Environment

If the driver was installed to a different Python (like the system default /usr/bin/python2.7), it won't be visible to /usr/local/bin/python. Install it directly for that environment:

  • First, ensure pip is available for /usr/local/bin/python:
    /usr/local/bin/python get-pip.py
    
  • Then install the compatible Cassandra driver version (Cassandra 3.6.0 works best with driver versions 3.6.x to 3.11.x):
    /usr/local/bin/pip install cassandra-driver==3.11.0
    
  • Verify the driver is installed:
    /usr/local/bin/python -c "from cassandra.cluster import Cluster; print('Cassandra driver loaded successfully!')"
    

4. Force cqlsh to Use the Correct Python Version

By default, cqlsh uses the Python instance found in your PATH, which might not be the one you fixed. You can override this in two ways:

  • Edit the cqlsh script: Locate the cqlsh executable (usually in /usr/bin/cqlsh or your Cassandra installation's bin directory). Open it and change the first line from:
    #!/usr/bin/env python
    
    To the path of your fixed Python instance, e.g.:
    #!/usr/local/bin/python
    
  • Run cqlsh with explicit Python: Alternatively, call cqlsh directly using the correct Python:
    /usr/local/bin/python /path/to/cqlsh
    

5. Double-Check System Python (Alternative)

If fixing /usr/local/bin/python feels too tedious, you can switch cqlsh to use the system default Python (/usr/bin/python2.7) instead:

  • Install the driver and zlib dev packages for the system Python:
    sudo yum install zlib-devel python-pip -y
    sudo pip install cassandra-driver==3.11.0
    
  • Then edit the cqlsh script to use /usr/bin/python2.7 as the shebang line.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 06:36:32