记录python安装chatterbot步骤和遇到的问题解决

本文介绍了如何在Python环境中安装和配置,包括Python3.8.8的安装,使用pip升级和安装依赖如chatterbot和spacy,以及创建和测试一个基于Chatterbot的计算器实例。还提及了解决可能遇到的依赖问题和语法错误.

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.安装python Python Release Python 3.8.8 | Python.orgThe official home of the Python Programming Languageicon-default.png?t=N7T8https://www.python.org/downloads/release/python-388/2.命令行 查看python是否安装成功

3.创建一个python项目,并打开

4.先更新pip版本,防止版本低更新不了

pip install --upgrade pip

5.依次安装依赖

pip install chatterbot==1.0.4  
pip install chatterbot-corpus  #语料库
pip install spacy 

6.创建test.py测试实例

from chatterbot import ChatBot

# naming the ChatBot calculator
# using mathematical evaluation logic
# the calculator AI will not learn with the user input
Bot = ChatBot(name = 'Calculator',
                read_only = True,                  
                logic_adapters = ["chatterbot.logic.MathematicalEvaluation"],                 
                storage_adapter = "chatterbot.storage.SQLStorageAdapter")
    

# clear the screen and start the calculator
print('\033c')
print("Hello, I am a calculator. How may I help you?")
while (True):
    # take the input from the user
    user_input = input("me: ")
    
    # check if the user has typed quit to exit the prgram   
    if user_input.lower() == 'quit':
        print("Exiting")
        break

    # otherwise, evaluate the user input
    # print invalid input if the AI is unable to comprehend the input
    try:
        response = Bot.get_response(user_input)
        print("Calculator:", response)
    except:
        print("Calculator: Please enter valid input.")

6.运行代码,

6.1 可能会报缺少 pytz 依赖,输入pip install pytz 下载依赖

6.2 可能会报 语法错误,打开 compat.py 将 time.clock 为:time.perf_counter()

重新运行即可成功!

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值