错误:“AttributeError: module 'aiml' has no attribute 'Kernel'
初学Python 3.X,按照网页上的关于aiml的例子写了如下代码,运行总是报错:
C:\Users\lenovo\PycharmProjects\aimltest\venv\Scripts\python.exe C:/Users/lenovo/PycharmProjects/aimltest/test1.py
Traceback (most recent call last):
File "C:/Users/lenovo/PycharmProjects/aimltest/test1.py", line 17, in <module>
alice=aiml.Kernel()
AttributeError: module 'aiml' has no attribute 'Kernel'
C:\Users\lenovo\PycharmProjects\aimltest\venv\lib\site-packages\aiml\alice
Process finished with exit code 1
检查了目录,aiml下面也有Kernel.py,请问如何解决,谢谢大侠!
-----------------------源代码------------------------------------
# -*- coding: utf-8 -*-
import aiml
import sys
import os
def get_module_dir (name):
path = getattr(sys.modules[name], '__file__', None)
if not path:
raise AttributeError('模块 %s 没有 属性 __file__'%name)
return os.path.dirname(os.path.abspath(path))
alice_path =get_module_dir('aiml') +'\\alice'
os.chdir(alice_path)
print(alice_path)
alice=aiml.Kernel()
alice.learn("std-startup.xml")
alice.respond("load aiml b")
while True:
print(alice.respond(input("Enter your message >>")))