繁体   English   中英

Chatterbot:AttributeError:模块“时间”没有属性“时钟”

[英]Chatterbot : AttributeError: module 'time' has no attribute 'clock'

我正在尝试创建一个聊天机器人,但由于我的电脑上没有安装最新版本的聊天机器人,所以我使用pip install chatterbot==1.0.4了聊天机器人,并且出现了以下错误。

我该如何解决这个问题?

下面是代码:

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'

你运行的是什么版本的 python? py 3.8+ 的time.clock已被删除

解决方案包括降级 python 或更改源代码:


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

自 3.3 版起已弃用,将在 3.8 版中删除:此 function 的行为取决于平台:根据您的要求使用 perf_counter() 或 process_time() 来获得明确定义的行为。

我不是专家,但您是否在代码顶部尝试过“导入时间”。 当我在 pythoncode 中使用 time.sleep() 时为我工作

我同意@Glycerine 的回答,好吧,如果你不想降级你的 python 版本,我有另一个解决方案给你。

打开文件 <Python-folder>\Lib\site-packages\sqlalchemy\util\compat.py Go 到第 264 行,其中指出:


if win32 or jython:
    time_func = time.clock
    
else:
    time_func = time.time

将其更改为:


if win32 or jython:
    #time_func = time.clock
    pass
else:
    time_func = time.time

简单来说,我们避免使用timer.clock方法和time_func object,因为我看到这个 object 只是白白创建,什么都不做。 它刚刚创建并保持不变。

我不知道为什么在没有用的情况下甚至会存在。 但这应该对你有用。

希望它有所帮助!

  1. 在您的站点包文件夹中打开sqlalchemycompat.py
  2. time.clock()替换为time.perf_counter()

这应该工作!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM