我正在尝试使用带有 python 的 aiml 构建聊天机器人

Am trying to built a chat bot using aiml with python

import aiml
import os
kernel = aiml.kernel()
if os.path.isfile("bot_brain.brn"):
    kernel.bootstrap(brainFile = "bot_brain.brn")
else:
    kernel.bootstrap(learnFiles = "std-startup.xml", commands = "load aiml b")
    kernel.savebrain("bot_brain.brn")
while True:
    print kernel.respond(raw_input("Enter Your Message")).strip()
aiml.kernel()

它抛出类似

的错误

回溯(最近调用最后): 文件“init.py”,第 3 行,位于 内核 = aiml.kernel() AttributeError: 'module' 对象没有属性 'kernel'

aiml.kernel() 应该是 aiml.Kernel()

请注意,aiml 包仅适用于 Python 2。GitHub 上的 Py3kAiml 是 Python 3 的替代方案。你也参考这个post.

运行 pip install python-aiml 不是pip install aiml