- Documentation
- Reference manual
- Packages
- SWI-Prolog Python interface
- Introduction
- Data conversion
- Janus by example
- library(janus): Call Python from Prolog
- Calling Prolog from Python
- Janus and threads
- Janus as a Python package
- Prolog and Python
- Janus performance evaluation
- Python or C/C++ for accessing resources?
- Janus platforms notes
- Compatibility to the XSB Janus implementation
- Status of Janus
- SWI-Prolog Python interface
7 Janus as a Python package
The Janus
GIT repo provides setup.py. Janus may be installed as a
Python package after downloading using
pip install .
pip allows for installation from the git repository in a one-liner as below.
pip install git+https://github.com/SWI-Prolog/packages-swipy.git#egg=janus_swi
Installing janus as a Python package requires
- The swipl program in the default search path. The
setup.pyrunsswipl --dump-runtime-variablesto obtain the installation locations of the various Prolog components. On Windows, if swipl is not on%PATH%,setup.pytries the registry to find the default binary installation. - A C compiler that can be used by pip. The janus interface has been tested to compile using GCC, Clang and Microsoft Visual C++.
After successful installation we should be able to use Prolog directly from Python. For example:
python
>>> from janus_swi import *
>>> once("writeln('Hello world!')")
Hello world!
{'truth': True}
>>> [a["D"] for a in Query("between(1,6,D)")]
[1, 2, 3, 4, 5, 6]
>>> prolog()
?- version.
Welcome to SWI-Prolog (threaded, 64 bits, version 9.1.12-8-g70b70a968-DIRTY)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
...
?-