Python3 - "NameError: ... " when importing from Experta

Python3 - "NameError: ... " when importing from Experta

你好,
我使用 Python 3.8.3 在 Conda 环境中安装了 Experta,我的所有程序都运行良好,但是当我尝试 运行 此代码导入 Experta 库时,出现以下错误:"NameError: name 'Fact' is not defined" .

from random import choice
from experta import *


class Light(Fact):
    """Info about the traffic light."""
    pass


class RobotCrossStreet(KnowledgeEngine):
    @Rule(Light(color='green'))
    def green_light(self):
        print("Walk")

    @Rule(Light(color='red'))
    def red_light(self):
        print("Don't walk")

    @Rule(AS.light << Light(color=L('yellow') | L('blinking-yellow')))
    def cautious(self, light):
        print("Be cautious because light is", light["color"])


engine = RobotCrossStreet()
engine.reset()
engine.declare(Light(color=choice(['green', 'yellow', 'blinking-yellow', 'red'])))
engine.run()

错误:

Traceback (most recent call last):
File "experta.py", line 2, in <module>
  from experta import *
File "/home/karuro/Documents/Magierin/UPN/IntelligentSystems/Experta/experta.py", line 5, in <module>
  class Light(Fact): 
NameError: name 'Fact' is not defined

谁能帮我解决这个问题?

检查是否安装了 experta,如果没有安装,请尝试使用 --user(root)

pip install experta --user

使用名称 "experta.py" 执行时出现问题。

解决方案:
使用不同的名称克隆文件并重新运行程序。