Reputation: 1
I have a question. In a Python project that uses pyswip to establish a connection with SWI-Prolog, is it possible to create an executable.exe for that project so that it can be run on other computers without necessarily having to install SWI-Prolog on them? That said, I'm working on a project where I need to establish a connection between Python and Prolog through pyswip, which is a graphical interface with tkinter where based on the data entered a specific query is generated to be performed on the knowledge base, something simple so to speak, but when creating an executable and running it on another computer it gives an error.
I try to create the executable using the command
pyinstaller --onefile --windowed --clean --hidden-import=pyswip --add-data "data/*;data" --add-data "swi-prolog/*;swi-prolog" --icon="data/icon_steel.ico" gui.py
In the "data" directory there is the knowledge base and other elements necessary for the interface and the "swi-prolog" directory corresponds to the portable version of swi-prolog that is located in PortableApps
In the python script the following lines have been implemented to temporarily create environment variables associated with the swi-prolog directory within the project ` from tkinter import Tk, Toplevel, Canvas, Entry, Button, PhotoImage, messagebox, Label from pathlib import Path from pyswip import Prolog import re, os, sys
if getattr(sys, 'frozen', False):
# El script está ejecutándose en un .exe
base_path = sys._MEIPASS
else:
# El script se está ejecutando de manera normal
base_path = os.path.dirname(os.path.abspath(__file__))
swi_prolog_path = base_path / 'swi-Prolog' / 'App' / 'SWI-Prolog'
os.environ['SWI_HOME_DIR'] = str(swi_prolog_path)
os.environ['PATH'] = str(swi_prolog_path / 'bin') + os.pathsep + os.environ['PATH']
# Direccionamiento de rutas
conocimientos_path = os.path.join(base_path, 'data', 'conocimientos.pl')
...`
I have shortened the script code, as the following lines correspond to interface design
After creating the project executable and trying to run it on another computer where Python and swi-prolog have not been installed, the following error occurs:
Traceback (most recent call last): File "gui.py", line 3, in <module> File "<frozen importlib._bootstrap>", line 1178, in _find_and_load File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 690, in _load_unlocked File "PyInstaller\loader\pyimod02_importers.py", line 384, in exec_module File "pyswip\__init__.py", line 29, in <module> File "<frozen importlib._bootstrap>", line 1178, in _find_and_load File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 690, in _load_unlocked File "PyInstaller\loader\pyimod02_importers.py", line 384, in exec_module File "pyswip\prolog.py", line 26, in <module> File "<frozen importlib._bootstrap>", line 1178, in _find_and_load File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 690, in _load_unlocked File "PyInstaller\loader\pyimod02_importers.py", line 384, in exec_module File "pyswip\core.py", line 510, in <module> File "pyswip\core.py", line 358, in _find_swipl File "pyswip\core.py", line 194, in _find_swipl_windows pyswip.core.SwiPrologNotFoundError: SWI-Prolog not found [PYI-484:ERROR] Failed to execute script 'gui' due to unhandled exception!
So is there any method to be able to create the executable so that it can be run in other places without having to install swi-prolog?
Upvotes: 0
Views: 70