chatterbot安装教程
前提安装好conda环境
win+R进入到cmd界面安装python虚拟环境
- 创建虚拟环境,必须使用3.7版本
conda create -n py_en python==3.7.3
- 激活环境
conda activate py_en
- 安装chatterbot
pip install chatterbot
pip install chatterbot-corpus
pip install chatterbot
-
下载支持的压缩包
下载地址: https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.3.1/en_core_web_sm-2.3.1.tar.gz文件存放目录我放在虚拟环境文件的上一级目录并运行下面命令
pip install en_core_web_sm-2.3.1.tar.gz
在虚拟环境文件夹中搜索site-packages,进入到en_core_web_sm,将里面的文件夹en_core_web_sm-2.3.1改名为en并复制en,放到运行程序的项目里。
其中,我的en_core_web_sm文件夹目录是:
anaconda3/envs/python3.7.3/lib/python3.7/site-packages/en_core_web_sm
- 运行案例
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
chatbot = ChatBot('Ron Obvious')
# Create a new trainer for the chatbot
trainer = ChatterBotCorpusTrainer(chatbot)
# Train the chatbot based on the english corpus
trainer.train("chatterbot.corpus.chinese")
lineCounter = 1
# 开始对话
while True:
print(chatbot.get_response(input("(" + str(lineCounter) + ") user:")))
lineCounter += 1