Problem using ChatterBot in Python: AttributeError 'time' has no attribute 'clock'

78 Views Asked by At

I have this code using the chatterbot third-party library:

from chatterbot.trainers import ChatterBotCorpusTrainer
import time
from time import perf_counter

# Import the chatterbot module
import chatterbot

# Create a ChatBot instance with the name
chatbotj = chatterbot.ChatBot('epicurus')

# Create an instance of the ChatterBotCorpusTrainer
trainer = ChatterBotCorpusTrainer(chatbotj)

# Train the chatbot using the Italian corpus
trainer.train('chatterbot.corpus.italian')

exit_conditions = (":q", "quit", "exit")
while True:
     query = input("> ")
     if query in exit_conditions:
         break
     else:
         response = chatbotj.get_response(query)
         print(response)

When I try using the code, I get an error like this from Visual Studio:

   Message=module 'time' has no attribute 'clock'
   Source=C:\Users\User\source\repos\PythonApplication5\PythonApplication5\PythonApplication5.py
   Stack Trace:
   File "C:\Users\User\source\repos\PythonApplication5\PythonApplication5\PythonApplication5.py", line 9, in <module> (Current frame)
     chatbotj = chatterbot.ChatBot('epicurus')
AttributeError: module 'time' has no attribute 'clock'

I have these packages installed:

ChatterBot==1.0.4
chatterbot-corpus==1.2.0
click==8.1.7
colorama==0.4.6
joblib==1.3.2
mathparse==0.1.2
nltk==3.8.1
Pint==0.22
pymongo==3.13.0
python-dateutil==2.7.5
pytz==2023.3.post1
PyYAML==3.13
regex==2023.8.8
six==1.16.0
SQLAlchemy==1.2.19
tqdm==4.66.1
typing_extensions==4.7.1

I tried both with Python 3.9 and 3.11 and with Chatterbot 1.0.5, installing all the individual packages separately after using --install --no-deps (because I had problems using pip install chatterbot --upgrade).

What is wrong, and how do I fix it?

1

There are 1 best solutions below

0
Mitchell Olislagers On

You're using an old version of sqlalchemy that relies on the now deprecated time.clock. See requirements.txt. Try updating it

pip install sqlalchemy --upgrade