python - Chatter Bot Corpus'Trainer' 缺失错误
问题描述
我正在尝试开始在 python 中构建聊天机器人。我真的很想从头开始编程。我从 ChatterBot 模块开始学习它是如何工作的。我已经 pip 安装了所有模块,但我仍然遇到“ChatterBotCorpusTrainer”的问题,我收到了一个丢失的错误。我运行 python 3.7 并且我有更新的 ChatBot 模块。
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
import os
bot= ChatBot('Bot')
trainer = ChatterBotCorpusTrainer(bot)
corpus_path = '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/chatterbot_corpus/data/english'
for file in os.listdir(corpus_path):
trainer.train(corpus_path + file)
conversation = [
"Hello",
"Hi there!",
"How are you doing?",
"I'm doing great.",
"That is good to hear",
"Thank you.",
"You're welcome."
]
trainer = ChatterBotCorpusTrainer(chatbot)
trainer.train('chatterbot.corpus.english')
response = chatbot.get_response("Good morning!")
print(response)
这是我得到的错误
/Users/singlefawn/Desktop/Our Realm/1997/Programs/random gallery/venv/lib/python3.7/site-packages/chatterbot/storage/jsonfile.py:26: UnsuitableForProductionWarning: The JsonFileStorageAdapter is not recommended for production environments.
self.UnsuitableForProductionWarning
Traceback (most recent call last):
File "/Users/singlefawn/Desktop/Our Realm/1997/Programs/random gallery/chat_1_1.py", line 6, in <module>
trainer = ChatterBotCorpusTrainer(bot)
File "/Users/singlefawn/Desktop/Our Realm/1997/Programs/random gallery/venv/lib/python3.7/site-packages/chatterbot/trainers.py", line 101, in __init__
from .corpus import Corpus
File "/Users/singlefawn/Desktop/Our Realm/1997/Programs/random gallery/venv/lib/python3.7/site-packages/chatterbot/corpus/__init__.py", line 6, in <module>
from chatterbot_corpus import Corpus
ImportError: cannot import name 'Corpus' from 'chatterbot_corpus' (/Users/singlefawn/Desktop/Our Realm/1997/Programs/random gallery/venv/lib/python3.7/site-packages/chatterbot_corpus/__init__.py)
解决方案
您需要指定模块(chatterbot.trainers)。您有 2 个选项:
1
from chatterbot import trainers
2
trainer = chatterbot.trainers.ChatterBotCorpusTrainer
推荐阅读
- wordpress - 在新域中托管后无法访问 wp-admin
- java - 在优先级队列中插入元素,具有优先级属性
- python - 将坐标循环成重复 len(x) 次的字符串
- python - 大文本编辑,粘贴替换
- sublimetext3 - 自定义 JSX 的 Emmet 缩写
- c++ - 解决错误:operator[] 不匹配
- aws-lambda - 无法在 AWS Lambda 中初始化 Dialogflow Fulfillment WebhookClient
- android - Gradle 同步失败:原因:未指定 compileSdkVersion
- python - 如何动态查询一个mongoDB文档
- haskell - 组合不同类型的流