python - 索引错误: list index out of range for pyswip library

标签 python prolog

首先,我现在遇到了太多 python 错误。这种情况对我的动力产生了相当负面的影响。我正在尝试运行在此错误中发现的专家系统。但我收到以下错误。我查看了其他解决方案,但它也不适合我。

药店专家系统: https://github.com/enzoftware/pyswipl_drugstore

代码:

from flask import Flask, render_template, flash, request
from wtforms import Form, TextField, TextAreaField, validators, StringField, SubmitField
from pyswip import Prolog
import os
import time

# App config.
DEBUG = True
app = Flask(__name__)
app.config.from_object(__name__)
app.config['SECRET_KEY'] = '7d441f27d441f27567d441f2b6176a'



class ReusableForm(Form):

    name = TextField('Name:', validators=[validators.required()])

    @app.route("/", methods=['GET', 'POST'])
    def hello():
        form = ReusableForm(request.form)
        if request.method == 'POST':

            name=request.form['name']
            fiebre = request.form.get('fiebre') == 'on'
            nausea = request.form.get('nausea') == 'on'
            diarrea = request.form.get('diarrea') == 'on'
            headache = request.form.get('headache') == 'on'
            print(fiebre, nausea, diarrea, headache)
            os.system('swipl -q -t "program" console.pl')
        if form.validate():
            f = open("file.txt", "r")
            disease = f.read()
            print(disease)
            flash('Hola ' + name + ', por tus sintomas podemos deducir que tienes '+ disease)
        else:
            flash('Error: Debes ingresar tu nombre. ')

        return render_template('hello.html', form=form)

if __name__ == "__main__":
    app.run()



错误:

ERROR: The system was unable to find the specified registry key or value.
Traceback (most recent call last):
  File "c:/Users/BAUM-PC/Desktop/Yeni klasör/pyswipl_drugstore-master/main.py", line 3, in <module>
    from pyswip import Prolog
  File "c:\Users\BAUM-PC\Desktop\Yeni klasör\pyswipl_drugstore-master\pyswip\__init__.py", line 29, in <module>
    from pyswip.prolog import Prolog
  File "c:\Users\BAUM-PC\Desktop\Yeni klasör\pyswipl_drugstore-master\pyswip\prolog.py", line 28, in <module>
    from pyswip.core import *
  File "c:\Users\BAUM-PC\Desktop\Yeni klasör\pyswipl_drugstore-master\pyswip\core.py", line 568, in <module>
    (_path, SWI_HOME_DIR) = _findSwipl()
  File "c:\Users\BAUM-PC\Desktop\Yeni klasör\pyswipl_drugstore-master\pyswip\core.py", line 411, in _findSwipl
    (path, swiHome) = _findSwiplWin()
  File "c:\Users\BAUM-PC\Desktop\Yeni klasör\pyswipl_drugstore-master\pyswip\core.py", line 208, in _findSwiplWin
    match = pattern.match(ret[-1])
IndexError: list index out of range

核心.py (相关部分)

    try:
        cmd = Popen(['reg', 'query',
            r'HKEY_LOCAL_MACHINE\Software\SWI\Prolog',
            '/v', 'home'], stdout=PIPE)
        ret = cmd.communicate()

        # Result is like:
        # ! REG.EXE VERSION 3.0
        #
        # HKEY_LOCAL_MACHINE\Software\SWI\Prolog
        #    home        REG_SZ  C:\Program Files\pl
        # (Note: spaces may be \t or spaces in the output)
        ret = ret[0].splitlines()
        ret = [line.decode("utf-8") for line in ret if len(line) > 0]
        pattern = re.compile('[^h]*home[^R]*REG_SZ( |\t)*(.*)$')
        match = pattern.match(ret[-1])
        if match is not None:
            path = match.group(2)

            paths = [os.path.join(path, 'bin', dllName)
                     for dllName in dllNames]
            for path in paths:
                if os.path.exists(path):
                    return (path, None)


最佳答案

Windows 解决方案:

  1. 确保您的 Python 和 SWI Prolog 都是 32 位或 64 位。

  2. 转到 core.py 的第 180 行并将该行更改为:

    paths = [os.path.join(programFiles, r'swipl\bin', dllName)

关于python - 索引错误: list index out of range for pyswip library,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59386690/

相关文章:

string - Prolog DCG 从字母数字字符构建/识别字符串

prolog - 将 prolog 集成到其他环境中

Prolog、失败且不回溯

python - 我如何比较 pandas 中具有相同类别的两个日期列

Python,缩放浮点范围 [0,1) 到 [min, max)

python - 在什么时候我可以将数组传递回我的 Rust 程序以释放它的内存?

python - Django:按[无,其他]中的值过滤

list - 在 Prolog 中查找所有列表旋转

python - Python中的关系/逻辑编程?

python - pip 安装的奇怪行为