I am trying to create a chatbot, but since latest version of chatterbot was not getting installed on my pc so I installed chatterbot by using pip install chatterbot==1.0.4
and the following error is showing up.
How do I resolve this?
Below is the code:
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
bot = ChatBot("My Bot")
convo = [
'hello',
'hi there',
'what is your name?',
'My name is BOT, I am created my a hooman ',
'how are you',
'i am doing great these days',
'thank you',
'in which city you live',
'i live in kalyan',
'in which languages do you speak',
'i mostly talk in english'
]
trainer=ListTrainer(bot)
trainer.train(convo)
print("Talk to Bot")
while True:
query=input()
if query=='exit':
break
answer=bot.get_response
print("bot : ", answer)
output:
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
PS E:\GIT VS CODE\Py> & D:/Python/python.exe "e:/GIT VS CODE/Py/chatbot.py"
Traceback (most recent call last):
File "e:\GIT VS CODE\Py\chatbot.py", line 4, in <module>
bot = ChatBot("My Bot")
File "D:\Python\lib\site-packages\chatterbot\chatterbot.py", line 34, in __init__
self.storage = utils.initialize_class(storage_adapter, **kwargs)
File "D:\Python\lib\site-packages\chatterbot\utils.py", line 54, in initialize_class
return Class(*args, **kwargs)
File "D:\Python\lib\site-packages\chatterbot\storage\sql_storage.py", line 22, in __init__
from sqlalchemy import create_engine
File "D:\Python\lib\site-packages\sqlalchemy\__init__.py", line 8, in <module>
from . import util as _util # noqa
File "D:\Python\lib\site-packages\sqlalchemy\util\__init__.py", line 14, in <module>
from ._collections import coerce_generator_arg # noqa
File "D:\Python\lib\site-packages\sqlalchemy\util\_collections.py", line 16, in <module>
from .compat import binary_types
File "D:\Python\lib\site-packages\sqlalchemy\util\compat.py", line 264, in <module> time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'
What version of python are you running? time.clock
has been removed for py 3.8+
Solutions include downgrading python or altering the source it seems:
AttributeError: module 'time' has no attribute 'clock' in Python 3.8
From the Python 3.8 doc:
The function time.clock() has been removed, after having been deprecated since Python 3.3: use time.perf_counter() or time.process_time() instead, depending on your requirements, to have well-defined behavior. (Contributed by Matthias Bussonnier in bpo-36895.)
Solution for - AttributeError: module 'time' has no attribute 'clock'
In Response to your comment: I'm assuming the chatterbox devs will fix this eventually but yes, downgrading to Python 3.7 will fix this: https://docs.python.org/3.7/library/time.html#time.clock
Deprecated since version 3.3, will be removed in version 3.8: The behaviour of this function depends on the platform: use perf_counter() or process_time() instead, depending on your requirements, to have a well defined behaviour.
Im not an expert, but have you tried 'import time' in the top of your code. Worked for me when I was using time.sleep() in my pythoncode
I agree with @Glycerine's answer, well, if you don't want to downgrade your python version, I have another solution for you.
Open the file <Python-folder>\Lib\site-packages\sqlalchemy\util\compat.py Go to line 264 which states:
if win32 or jython:
time_func = time.clock
else:
time_func = time.time
Change it to:
if win32 or jython:
#time_func = time.clock
pass
else:
time_func = time.time
Simply here we are avoiding the use of timer.clock
method and the time_func
object because I saw that this object is just created for nothing and does nothing. It is just created and left untouched.
I don't know why even this exists when it is of no use. But this should work for you.
Hope it helped!
- Open compat.py of sqlalchemy in your site-packages folder.
- Replace time.clock() with time.perf_counter() .
This should work !
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.