python - Python3 - 从 Experta 导入时出现“NameError: ...”
问题描述
您好,
我使用 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
推荐阅读
- api - 如果 graphql 是一种查询语言,为什么它用在前端而不是后端?
- apify - PuppeteerCrawler 和 Task 的 Settigs 差异
- oracle - PLS-00103:结束而不是编译指示最终实例化顺序覆盖静态成员构造函数映射
- java - JSP 代码超出了 65535 字节的限制 - Tomcat 9 修复
- android - 只要应用程序打开,如何使用socket.io保持活跃的android webview
- java - 哪些声明是有效的?
- php - Foreach 循环和 cURL 请求的问题
- json - 在句子(句子数组)中的任何位置找到确切的两个单词 elastcsearch 6.8
- c# - 如何在 Unity 上的 Google OnAdclose 上访问从一个 GameObject 到另一个 GameObject 的方法?
- laravel-5 - 数据表 - 用图标替换值适用于一个单元格而不是两个单元格