I have already using pip install weaviate-client
, and I checked my python version is 3.10.5. docker has been running with the ‘weaviate’ and a text2vec transformer called ‘t2v-transformers’images
When I run the code below, it returned from weaviate import * ModuleNotFoundError: No module named 'weaviate'
from weaviate import *
import json
client = Client(
url = "http://localhost:8080/",
)
# specify schema for the data we'll be using
client.schema.delete_class("SimSearch")
class_obj = {
"class": "SimSearch",
"vectorizer": "text2vec-transformers"
}
client.schema.create_class(class_obj)
# download data
import requests
url = 'http://localhost:8000/data.json'
resp = requests.get(url)
data = json.loads(resp.text)
# send data to weaviate, to vectorize
with client.batch as batch:
batch.batch_size=100
# Batch import all data
for i, d in enumerate(data):
print(f"nimporting datum: {i}")
properties = {
"answer": d["Answer"],
"question": d["Question"],
"category": d["Category"],
}
print(f"properties: {properties}")
client.batch.add_data_object(properties, "SimSearch")
it returned from weaviate import * ModuleNotFoundError: No module named 'weaviate'
Duda from Weaviate here.
This is not the proper way to import the weaviate client (both client v3 and v4)
From our Quick Start (for v4 client)
import weaviate
import weaviate.classes as wvc
import os
import requests
import json
client = weaviate.connect_to_wcs(
cluster_url=os.getenv("WCS_URL"),
auth_credentials=weaviate.auth.AuthApiKey(os.getenv("WCS_API_KEY")),
headers={
"X-OpenAI-Api-Key": os.environ["OPENAI_APIKEY"] # Replace with your inference API key
}
)
try:
pass # Replace with your code. Close client gracefully in the finally block.
finally:
client.close() # Close client gracefully
if you are using a local instance, without auth, you can replace weaviate.connecto_to_wcs
with weaviate.connect_to_local
without any parameters
Let me know if this helps!
Thanks!