安装 chatterbot
pip install chatterbot
如果是python 3.7 安装会成功 使用会出现错误
建议换成python3.6.4
还是执行 pip install chatterbot
如果遇到错误:
PermissionError: [WinError 32] 另一个程序正在使用此文件,进程无法访问。: 'D:\\Users\\zhangsan\\AppData\\Local\\Temp\\pip-build-v66ub_xf\\sqlalchemy\\build\\lib.win-amd64-3.6\\sqlalchemy\\cutils.cp36-win_amd64.pyd'
需要更改编码。
解决方法:
打开你自己的python的包路径,例如:
c:\program files\python36\lib\site-packages\pip\compat_init_.py 约75行
return s.decode('utf_8') 改为return s.decode('cp936')
原因:
编码问题,虽然py3统一用utf-8了。但win下的终端显示用的还是gbk编码。
run的时候
如果提示 缺少 chatterbot_corpus 模块
pip install chatterbot_corpus
测试代码:
rom 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)