CentOS7运行cqlsh报错:Python Cassandra driver未安装/Zlib不可用求助
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:
- Grab the Python 2.7.6 source code, extract it, and navigate to the source directory
- Run the configure command with zlib enabled:
./configure --prefix=/usr/local --with-zlib - 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/cqlshor your Cassandra installation'sbindirectory). Open it and change the first line from:
To the path of your fixed Python instance, e.g.:#!/usr/bin/env python#!/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.7as the shebang line.
内容的提问来源于stack exchange,提问作者Ganesh

