JonathanA001
JonathanA001

Reputation: 11

Cassandra Python app on Windows returns "The C extension needed to use libev was not found"

Once I saw an ad about how to make an AI generated your own adventure game in Python, so I went to YouTube and checked the video out. Even though the video was out of date, I followed along with it pretty well. But when I tried to run a set of Python code that is downloaded from here, in particular

from cassandra.cluster import Cluster

I got an error :

Traceback (most recent call last):
  File "C:\Users\xxxxx\Desktop\My_Database\tutorial.py", line 1, in <module>
    from cassandra.cluster import Cluster
  File "cassandra\cluster.py", line 173, in init cassandra.cluster
cassandra.DependencyException: Unable to load a default connection class
The following exceptions were observed:
 - The C extension needed to use libev was not found.  This probably means that you didn't have the required build dependencies when installing the driver.  See http://datastax.github.io/python-driver/installation.html#c-extensions for instructions on installing build dependencies and building the C extension.
 - Unable to import asyncore module.  Note that this module has been removed in Python 3.12 so when using the driver with this version (or anything newer) you will need to use one of the other event loop implementations. 

Even though I searched the problem up and found a lot of similar problems that are solved,but none of them is working for me,so I went here and hope someone solves my problem.

When I runs the code,I expect It's going to work out like the video showed,but it didn't.Even though I searched the problem up and found a lot of similar problems that are solved,but none of them is working for me,so I went here and hope someone solves my problem.

Upvotes: 1

Views: 583

Answers (1)

Aaron
Aaron

Reputation: 57798

That's really strange. Those dependencies should be taken care of when you run pip3 install cassandra-driver.

I'd be curious to know the outputs of both:

python3 --version

and

python3 -c 'import cassandra; print (cassandra.__version__)'

In theory, the last command should invoke the same error you are reporting. But in the video Tim is running on Python 3.9.6, and I tested it on both 3.9.6 and 3.12.1. I'd make sure that you're at least on 3.9.6.

You may want to have a look at the DataStax docs on the Python driver, especially the part about the C extensions. There might be something there that can fix this.

Otherwise I've create a simpler version of the connect_database.py (from the doc mentioned above). It will work as long as environment variables for ASTRA_TOKEN and ASTRA_SCB are properly set.

from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider
from os import path, environ

import json

ASTRA_DB_APPLICATION_TOKEN = environ.get("ASTRA_TOKEN")
ASTRA_DB_SECURE_BUNDLE_PATH = environ.get("ASTRA_SCB")

cluster = Cluster(
    cloud={
        "secure_connect_bundle": ASTRA_DB_SECURE_BUNDLE_PATH,
    },
    auth_provider=PlainTextAuthProvider(
        "token",
        ASTRA_DB_APPLICATION_TOKEN,
    ),
)

session = cluster.connect()

row = session.execute("select release_version from system.local").one()
if row:
    print(row[0])
else:
    print("An error occurred.")

Output should look like this when connecting to Astra DB:

» python3 connect_database.py
4.0.11-df8e587a0e77

Upvotes: 1

Related Questions