Search code examples
pythonimportcondanameerrorpython-3.8

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


Hello,
I installed Experta in a Conda environment using Python 3.8.3 and all my programs work fine, but when I try to run this code importing Experta libraries I am having the following error: "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()

Error:

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

Can anyone help me fix this?


Solution

  • Problem executing with the name "experta.py".

    Solution:
    Clone the file with a different name and rerun the program.