我当前正在使用基本操作系统,并且试图弄清楚如何在python中使用Chatterbot库。
我已经使用以下命令安装了chatterbot库:
sudo pip3 install chatterbot
我还安装了chatterbot-corpus:
pip install chatterbot-corpus
当我尝试使用chatterbot运行此代码时:
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
# Create a new chat bot named Charlie
chatbot = ChatBot('Charlie')
trainer = ListTrainer(chatbot)
trainer.train([
"Hi, can I help you?",
"Sure, I'd like to book a flight to Iceland.",
"Your flight has been booked."
])
# Get a response to the input text 'I would like to book a flight.'
response = chatbot.get_response('I would like to book a flight.')
print(response)
它显示此错误消息:
Traceback (most recent call last):
File "/home/johndoe/chat.py", line 1, in <module>
from chatterbot import ChatBot
File "/usr/local/lib/python3.6/dist-packages/chatterbot/__init__.py", line 4, in <module>
from .chatterbot import ChatBot
File "/usr/local/lib/python3.6/dist-packages/chatterbot/chatterbot.py", line 2, in <module>
from chatterbot.storage import StorageAdapter
File "/usr/local/lib/python3.6/dist-packages/chatterbot/storage/__init__.py", line 1, in <module>
from chatterbot.storage.storage_adapter import StorageAdapter
File "/usr/local/lib/python3.6/dist-packages/chatterbot/storage/storage_adapter.py", line 3, in <module>
from chatterbot.tagging import PosHypernymTagger
File "/usr/local/lib/python3.6/dist-packages/chatterbot/tagging.py", line 4, in <module>
from chatterbot.tokenizers import get_sentence_tokenizer
File "/usr/local/lib/python3.6/dist-packages/chatterbot/tokenizers.py", line 4, in <module>
from chatterbot.corpus import load_corpus, list_corpus_files
File "/usr/local/lib/python3.6/dist-packages/chatterbot/corpus.py", line 5, in <module>
from chatterbot_corpus.corpus import DATA_DIRECTORY
ModuleNotFoundError: No module named 'chatterbot_corpus
尝试了以下Web解决方案:https://github.com/gunthercox/ChatterBot/issues/833
没有用。
我该如何解决?Screenshot of my Code
答案 0 :(得分:1)
I suggest to use pip3 install chatterbot-corpus I think you installed chatterbot on python3 and chatterbot-corpus on python2