首页 > 解决方案 > Python 聊天机器人未运行

问题描述

from chatterbot.trainers import ListTrainer
from chatterbot import ChatBot

bot = ChatBot('Buddy')
bot.set_trainer(ListTrainer)
conversation = open('chats.txt','r').readlines()
bot.train(conversation)
while True:
 message = input('You:')
 if message.strip() != 'Bye':
  reply = bot.get_response(message)
 print('ChatBot:', reply)
 if message.strip() == 'Bye':
  print('ChatBot:Bye')
  break

我尝试尝试显示错误消息的代码,请帮助我

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2020.3.5\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2020.3.5\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "F:/Work/PythonNLPExample/chatbot.py", line 4, in <module>
    bot = ChatBot('Buddy')
  File "F:\Work\PythonNLPExample\venv\lib\site-packages\chatterbot\chatterbot.py", line 34, in __init__
    self.storage = utils.initialize_class(storage_adapter, **kwargs)
  File "F:\Work\PythonNLPExample\venv\lib\site-packages\chatterbot\utils.py", line 54, in initialize_class
    return Class(*args, **kwargs)
  File "F:\Work\PythonNLPExample\venv\lib\site-packages\chatterbot\storage\sql_storage.py", line 46, in __init__
    if not self.engine.dialect.has_table(self.engine, 'Statement'):
  File "F:\Work\PythonNLPExample\venv\lib\site-packages\sqlalchemy\dialects\sqlite\base.py", line 1999, in has_table
    info = self._get_table_pragma(
  File "F:\Work\PythonNLPExample\venv\lib\site-packages\sqlalchemy\dialects\sqlite\base.py", line 2521, in _get_table_pragma
    cursor = connection.exec_driver_sql(statement)
AttributeError: 'Engine' object has no attribute 'exec_driver_sql'

标签: pythonchatterbot

解决方案


推荐阅读