python - IndexError:pyswip 库的列表索引超出范围
问题描述
首先,我现在遇到了太多关于 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
core.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)
解决方案
视窗解决方案:
确保您的 Python 和 SWI Prolog 都是 32 位或 64 位的。
转到 core.py 的第 180 行并将该行更改为:
paths = [os.path.join(programFiles, r'swipl\bin', dllName)
推荐阅读
- java - Java:在 Android Studio 中替换片段时如何保存用户输入的 EditText 和 TextViews?
- node.js - Material-ui 官方 SSR 示例在生产服务器中不起作用
- hyperledger-fabric - Hyperledger Fabric:可以使用fabric-python-sdk将交易提案转发给另一个节点的背书节点吗?
- mysql - MySQL将分离的月份和年份转换为新字段
- c++ - QtConcurrent 块 UI
- c# - 基本 Stream/StreamReader 类中没有同步的非阻塞读取方法
- php - Laravel 流明错误:在全栈 laravel 框架中实现流明时出错
- proxy - Keycloak 作为 Apache2 背后的子资源
- node.js - 正在寻找修复
- python - 为什么我的烧瓶应用程序没有在 formpage.html 中发布帖子?