# How to embed Python into Prolog on MacOS?

**URL:** <https://swi-prolog.discourse.group/t/how-to-embed-python-into-prolog-on-macos/8766>\
**Category:** Pack\
**Tags:** how-to\
**Created:** [February 2, 2025, 4:39pm UTC](https://swi-prolog.discourse.group/t/how-to-embed-python-into-prolog-on-macos/8766 "2025-02-02T16:39:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AZH](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/azh/32/6831_2.png) [@AZH](https://swi-prolog.discourse.group/u/AZH)\
**Post date:** [February 2, 2025, 4:39pm UTC](https://swi-prolog.discourse.group/t/how-to-embed-python-into-prolog-on-macos/8766/1 "2025-02-02T16:39:54Z")

</div>

Hello there!

After reading the README of Janus-SWI [GitHub - SWI-Prolog/packages-swipy: Python interface for SWI-Prolog](https://github.com/SWI-Prolog/packages-swipy) , I am still unsure how to embed Python into Prolog on MacOS. Do I need to install a Homebrew or Macports version of Python, in order to embed Python into Prolog?

My current Python was not installed through Homebrew or Macports. When I use `?- py_version.` I get `ERROR: Unknown procedure: janus:py_call/2`.

Is it simply because I am not using a Homebrew/Macports version of Python, or something else that I missed doing?

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [February 3, 2025, 9:21am UTC](https://swi-prolog.discourse.group/t/how-to-embed-python-into-prolog-on-macos/8766/2 "2025-02-03T09:21:18Z")

</div>

The Prolog library(janus) loads the foreign module `janus.so` that is bundled with SWI-Prolog. Using MacOS `otool -L`, we see this in turn binds to

```
 /Library/Frameworks/Python.framework/Versions/3.11/Python

```

As well as to Prolog and `libSystem.B.dylib`

For short, you need the thing that provides the Python framework, which is provided by the official installer from [Python.org](http://Python.org) (version 3.11).

Alternatively, the simplest is to use Macports and install SWI-Prolog 9.3.19 (devel). That will install Macports Python as a dependency and all should work out of the box.

As is, `library(janus)` is only built as part of a full build of SWI-Prolog. Possibly we should seek for some way to simplify dealing with the dependencies. I’m not sure how though. We could distribute an object file that relies on an old base version of Python (3.6) and do the final linking at install time. That still requires Xcode command line tools installed though. If anyone has an idea, please share.

---

<div class="post-metadata">

**Author:** ![AZH](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/azh/32/6831_2.png) [@AZH](https://swi-prolog.discourse.group/u/AZH)\
**Post date:** [February 3, 2025, 10:20am UTC](https://swi-prolog.discourse.group/t/how-to-embed-python-into-prolog-on-macos/8766/3 "2025-02-03T10:20:42Z")

</div>

Thank you very much Jan! It works perfectly!  
Problem solved after reinstalling Python 3.11 and then SWI-Prolog 9.3.19.
