0

I want to use pyswip in my project. I tried to install pyswip via Pycharm. It can be installed successfully.

  • OS: Windows 10 64-bit
  • IDE: Pycharm 2018.3.2
  • Language: Python 3.7
  • Pyswip Version: 0.2.7

The problem is when I tried to run a quick running test (The sample code below taken from Pyswip installation guide)

from pyswip import Prolog
prolog = Prolog()
prolog.assertz("father(michael,john)")

An error appeared

ERROR: The system was unable to find the specified registry key or value.
Traceback (most recent call last):
  File "C:/Users/Coregame/PycharmProjects/Project1/test.py", line 1, in <module>
from pyswip import Prolog
  File "C:\Users\Coregame\PycharmProjects\Project1\venv\lib\site-packages\pyswip\__init__.py", line 29, in <module>
from pyswip.prolog import Prolog
  File "C:\Users\Coregame\PycharmProjects\Project1\venv\lib\site-packages\pyswip\prolog.py", line 28, in <module>
from pyswip.core import *
  File "C:\Users\Coregame\PycharmProjects\Project1\venv\lib\site-packages\pyswip\core.py", line 568, in <module>
(_path, SWI_HOME_DIR) = _findSwipl()
  File "C:\Users\Coregame\PycharmProjects\Project1\venv\lib\site-packages\pyswip\core.py", line 411, in _findSwipl
(path, swiHome) = _findSwiplWin()
  File "C:\Users\Coregame\PycharmProjects\Project1\venv\lib\site-packages\pyswip\core.py", line 208, in _findSwiplWin
    match = pattern.match(ret[-1])
IndexError: list index out of range

What should I do? Thanks in advance!

Coregame
  • 1
  • 3
  • Are you in the class where the teacher wants you to have one language talk to another? If so take the easy way out. Pick two languages based on the same virtual machine, e.g. Java and Scala for JVM, or C# and F# for .Net. – Guy Coder Dec 21 '18 at 15:28
  • Of interest: [Language interoperability](https://en.wikipedia.org/wiki/Language_interoperability) – Guy Coder Dec 21 '18 at 15:31
  • Are you in a class with this person of this [question](https://stackoverflow.com/q/53877772/1243762)? These questions are rare and started poping up quite often here. – Guy Coder Dec 21 '18 at 15:38
  • @GuyCoder I'm not in the same class with that person. I take an AI course and my professor told me that I should use only SWI-Prolog and Python (if any). So pyswip is an only option. – Coregame Dec 21 '18 at 18:25
  • You have to use SWI-Prolog with Python. Never here of such a requirement. I use both SWI-Prolog and Python for AI but not together. I use SWI-Prolog for [closed world](https://en.wikipedia.org/wiki/Closed-world_assumption) problems and Python with Neural Networks for other open ended problems. If I were you I would check with the teacher to see if that is what they really mean. – Guy Coder Dec 21 '18 at 18:40

3 Answers3

1

In addition to making sure your Python and SWI Prolog are both 32- or 64-bit, SWI Prolog's bin folder needs to be in your system path so that Python's import can find it. You can do this in your Python script like so:

swipath = 'C:\\Program Files\\swipl\\bin'
import os
os.environ['PATH'] = swipath + os.pathsep + os.environ['PATH']

Just make sure to put this above your import Prolog statement.

Alternately, edit the "Path" environment variable for your account through the windows settings app by searching "Edit environment variables for your account", double-click "Path", click the "New" button and browse or type in the full path to your swipl\bin folder, then click "OK".

ken_oakbe
  • 11
  • 1
0

You're likely using 64bit pyswip with 32 bit SWI Prolog installed. Install the 64 bit SWI Prolog from here and it should solve the problem although you won't be able to use SWI Prolog editor.

Marij Khan
  • 151
  • 1
  • 12
0

I met this error before because my Python is 64bit, so I just installed the 32bit Python and it works.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263