# Setting up swiplserver for the first time. Help needed

**URL:** <https://swi-prolog.discourse.group/t/setting-up-swiplserver-for-the-first-time-help-needed/4697>\
**Category:** Help!\
**Tags:** how-to\
**Created:** [December 1, 2021, 4:47pm UTC](https://swi-prolog.discourse.group/t/setting-up-swiplserver-for-the-first-time-help-needed/4697 "2021-12-01T16:47:25Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ferdasonmez](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ferdasonmez/32/3578_2.png) [@ferdasonmez](https://swi-prolog.discourse.group/u/ferdasonmez)\
**Post date:** [December 1, 2021, 4:47pm UTC](https://swi-prolog.discourse.group/t/setting-up-swiplserver-for-the-first-time-help-needed/4697/1 "2021-12-01T16:47:25Z")

</div>

Hello Everyone,  
I have been using prolog in my python application for a while now. I am very happy using it. Since now, I was providing input to my app from a file. Recently I developed a Flask based web front end for this app. Unfortunetely, when I try to start my application via web I get Access Violation error at the point where Prolog initializes itself and reads the pl file.

The exact line that gets the error is below.

prolog.consult(’./graph\_traversal.pl’)

The error is :

OSError: exception: access violation reading 0x0000000000000050

I would appreciate any help (preferable a quick one) cause I have a demo tomorrow.

Kind Regards,  
Ferda

---

<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:** [December 2, 2021, 8:22am UTC](https://swi-prolog.discourse.group/t/setting-up-swiplserver-for-the-first-time-help-needed/4697/2 "2021-12-02T08:22:29Z")

</div>

This uses pyswip? The first things that codes to mind is threading. Most likely the recent MQI interface provided by @ericzinda is a safer alternative. Well, maybe pyswip users have other clues.

---

<div class="post-metadata">

**Author:** ![ericzinda](https://avatars.discourse-cdn.com/v4/letter/e/b3f665/32.png) [@ericzinda](https://swi-prolog.discourse.group/u/ericzinda)\
**Post date:** [December 2, 2021, 4:01pm UTC](https://swi-prolog.discourse.group/t/setting-up-swiplserver-for-the-first-time-help-needed/4697/3 "2021-12-02T16:01:12Z")

</div>

I can’t help with the (presumably) pyswip issue above, but I can validate that the [swiplserver](https://pypi.org/project/swiplserver/) Python library (the Python library that uses the MQI interface that @jan mentions) works well in a Flask application. That’s how I’ve been using it.

---

<div class="post-metadata">

**Author:** ![ferdasonmez](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ferdasonmez/32/3578_2.png) [@ferdasonmez](https://swi-prolog.discourse.group/u/ferdasonmez)\
**Post date:** [December 2, 2021, 4:17pm UTC](https://swi-prolog.discourse.group/t/setting-up-swiplserver-for-the-first-time-help-needed/4697/4 "2021-12-02T16:17:50Z")

</div>

Ok, Thank you I will modify the code to try this library.

---

<div class="post-metadata">

**Author:** ![ferdasonmez](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ferdasonmez/32/3578_2.png) [@ferdasonmez](https://swi-prolog.discourse.group/u/ferdasonmez)\
**Post date:** [December 5, 2021, 6:39pm UTC](https://swi-prolog.discourse.group/t/setting-up-swiplserver-for-the-first-time-help-needed/4697/5 "2021-12-05T18:39:30Z")

</div>

Hello Again,  
I couldn’t install this swipl. What is the correct repository link? I would appreciate if you can share…

Kind Regards,  
Ferda

---

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [December 5, 2021, 6:49pm UTC](https://swi-prolog.discourse.group/t/setting-up-swiplserver-for-the-first-time-help-needed/4697/6 "2021-12-05T18:49:12Z")

</div>

On the prolog side you don’t have to install anything, it is included in the latest SWI-Prolog version. Make sure to use the development version (8.5.3), which has recent fixes.

---

<div class="post-metadata">

**Author:** ![ferdasonmez](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ferdasonmez/32/3578_2.png) [@ferdasonmez](https://swi-prolog.discourse.group/u/ferdasonmez)\
**Post date:** [December 5, 2021, 7:16pm UTC](https://swi-prolog.discourse.group/t/setting-up-swiplserver-for-the-first-time-help-needed/4697/7 "2021-12-05T19:16:54Z")

</div>

Hi,  
I do not want to deal with building etc. now. The latest windows installer has the version 8.4.1.1. Is it ok?

Kind Regards,  
Ferda

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [December 5, 2021, 7:25pm UTC](https://swi-prolog.discourse.group/t/setting-up-swiplserver-for-the-first-time-help-needed/4697/8 "2021-12-05T19:25:27Z")

</div>

> [@ferdasonmez](#):
>
> The latest windows installer has the version 8.4.1.1.

To be more specific, that is the stable version. [https://www.swi-prolog.org/download/stable](https://www.swi-prolog.org/download/stable)

The installation, not build, for the Windows development version can be found at [https://www.swi-prolog.org/download/devel](https://www.swi-prolog.org/download/devel) which is currently at 8.5.3-1.

For an even more recent Windows version, is the nightly build found at [https://www.swi-prolog.org/download/daily/bin/](https://www.swi-prolog.org/download/daily/bin/)

* * *

This is also documented at

[Install SWI-Prolog development version on Windows 10](https://swi-prolog.discourse.group/t/install-swi-prolog-development-version-on-windows-10/1131)

* * *

HTH

---

<div class="post-metadata">

**Author:** ![ferdasonmez](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ferdasonmez/32/3578_2.png) [@ferdasonmez](https://swi-prolog.discourse.group/u/ferdasonmez)\
**Post date:** [December 5, 2021, 8:58pm UTC](https://swi-prolog.discourse.group/t/setting-up-swiplserver-for-the-first-time-help-needed/4697/9 "2021-12-05T20:58:57Z")

</div>

Hello,  
How do we consult with swiplserver. I couldn’t see a sample?

Thanks in advance.  
Ferda

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [December 5, 2021, 9:18pm UTC](https://swi-prolog.discourse.group/t/setting-up-swiplserver-for-the-first-time-help-needed/4697/10 "2021-12-05T21:18:44Z")

</div>

Maybe it is just me but this statement has me confused.

> [@ferdasonmez](#):
>
> How do we consult with swiplserver.

To me it could mean 1 of 2 different things.

* * *

1. 

To consult a Prolog source code file from the top level, see [Getting started quickly](https://www.swi-prolog.org/pldoc/man?section=quickstart)

* * *

1. 

To access a page from an SWI-Prolog web server just access the page like any others.

Typically the server will run locally and use a specific port, e.g. `8080`, and have an `index.html` page. So using your favorite web browser the URL would be `http://localhost:8080/index.html`

---

<div class="post-metadata">

**Author:** ![ferdasonmez](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ferdasonmez/32/3578_2.png) [@ferdasonmez](https://swi-prolog.discourse.group/u/ferdasonmez)\
**Post date:** [December 5, 2021, 9:45pm UTC](https://swi-prolog.discourse.group/t/setting-up-swiplserver-for-the-first-time-help-needed/4697/11 "2021-12-05T21:45:33Z")

</div>

Hi Eric,  
Thanks for the quick response. I am relatively new to the terminology, so I may be asking in a confusing way. Sorry for that.  
What I was asking is the equivalent of prolog.consult (pl\_file\_name\_and\_path) (where prolog is type of Prolog class) in this system.

I assume I would do this with exec in python but not sure.

How about the assertz function? Cause part of (static ones) my prolog definitions are in a pl file, but for part of them (dynamic ones depending on user input), I was using the assertz function to extend the initial definitions. I do all of this stuff as a part of initializing prolog in my system. Later, I do the queries…

I would appreciate if you can provide more detailed examples on how to use the pl file and how to do the assertz with this new swiplserver in python? I think the query part is relatively more straightforward.

Kind Regards,  
Ferda

---

<div class="post-metadata">

**Author:** ![ferdasonmez](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ferdasonmez/32/3578_2.png) [@ferdasonmez](https://swi-prolog.discourse.group/u/ferdasonmez)\
**Post date:** [December 5, 2021, 11:57pm UTC](https://swi-prolog.discourse.group/t/setting-up-swiplserver-for-the-first-time-help-needed/4697/12 "2021-12-05T23:57:34Z")

</div>

Hi Eric,  
As I described in my initial question, my prolog code and my interaction with it via python works well without the web interface, but has problem (access violation) when accessed via web. So, I need to have a sample working not on the command line but via python and swiplserver. Unfortunately, the getting starting guide does not provide an answer to my query. I have been trying to solve this problem using only the pyswip for a while now with no result.  
I understand that swiplserver package solves this problem, but I still can not understand how to use it properly. I can not find the functions that are necessary for my solution, basically **assertz** and **consult**. I am assuming **query** would work in a similar way pyswip. Couldn’t try it yet due to not passing the initialization phase… Hopefully you can help me to learn to use this new package?

Kind Regards,  
Ferda

---

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [December 6, 2021, 1:55am UTC](https://swi-prolog.discourse.group/t/setting-up-swiplserver-for-the-first-time-help-needed/4697/13 "2021-12-06T01:55:53Z")

</div>

Did you read the documentation here: [swiplserver · PyPI](https://pypi.org/project/swiplserver/) and here: [swiplserver.prologmqi API documentation](https://www.swi-prolog.org/packages/mqi/prologmqi.html)?

It seems rather simple python code:

```prolog
from swiplserver import PrologMQI, PrologThread

with PrologMQI() as mqi:
    with mqi.create_thread() as prolog_thread:
        result = prolog_thread.query("member(X, [color(blue), color(red)])")
        print(result)

```

EDIT: seems to me you just replace `"member[X, ...]"` with `consult(...)` or `assertz(...)`.

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [December 6, 2021, 6:49am UTC](https://swi-prolog.discourse.group/t/setting-up-swiplserver-for-the-first-time-help-needed/4697/14 "2021-12-06T06:49:01Z")

</div>

> [@EricGT](#):
>
> Maybe it is just me but this statement has me confused.

After seeing links by SWI it now makes sense.

> [@swi](#):
>
> Did you read the documentation here: [swiplserver · PyPI](https://pypi.org/project/swiplserver/) and here: [swiplserver.prologmqi API documentation](https://www.swi-prolog.org/packages/mqi/prologmqi.html)?

[mqi](https://www.swi-prolog.org/pldoc/doc_for?object=section(%27packages/mqi.html%27)) is only a few months old and I have not used it yet, thus my confustion. ☹

To make the terms mqi and swiplserver easier to understand when used in a topic here have added them as linkify terms. ([ref](https://swi-prolog.discourse.group/t/post-for-testing-installed-component-themes-and-plugins/2358#linkify-words-in-posthttpsmetadiscourseorgtlinkify-words-in-post82193-5))

If you look at the use of the term in earlier replies you will see that they have all magickly turned into links. 😉

---

<div class="post-metadata">

**Author:** ![ferdasonmez](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ferdasonmez/32/3578_2.png) [@ferdasonmez](https://swi-prolog.discourse.group/u/ferdasonmez)\
**Post date:** [December 6, 2021, 3:18pm UTC](https://swi-prolog.discourse.group/t/setting-up-swiplserver-for-the-first-time-help-needed/4697/15 "2021-12-06T15:18:20Z")

</div>

Thanks for the response. I tried to replace with consult now. Now I am getting the below error which seems to be related to configuration of MQServer.  
I saw some  
site-packages\swiplserver\prologmqi.py", line 428, in start

```
raise PrologLaunchError("no port found in stdout")

```

swiplserver.prologmqi.PrologLaunchError: no port found in stdout

I tried to run the below command with and without the halt hoping to have a running mq server but it didn’t help.

Please tell me what I am doing wrong?

---

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [December 6, 2021, 5:59pm UTC](https://swi-prolog.discourse.group/t/setting-up-swiplserver-for-the-first-time-help-needed/4697/16 "2021-12-06T17:59:58Z")

</div>

Run the folowing

```prolog
$ swipl --quiet -g mqi_start -t halt -- --write_connection_values=true   

```

You should see some output like:

```prolog
38515
149542373205988535753366437482310558445

```

The first number is the port.

If you don’t see the numbers, there is your problem.

---

<div class="post-metadata">

**Author:** ![ferdasonmez](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ferdasonmez/32/3578_2.png) [@ferdasonmez](https://swi-prolog.discourse.group/u/ferdasonmez)\
**Post date:** [December 6, 2021, 6:00pm UTC](https://swi-prolog.discourse.group/t/setting-up-swiplserver-for-the-first-time-help-needed/4697/17 "2021-12-06T18:00:11Z")

</div>

Hi Again,  
I was thinking MQI as a self starter. However, it didn’t in my case. Getting the MQI start error port not found, I decided to execute the below command hoping to start it manually.

`> os.system("swipl -s ./mqi.pl -g \"mqi:install_to_library('./mqi.pl')\" ")`

When I look at the python requirements, there is not much. I added the lib and library folders for both swi-prolog and swipl to the path. Anyway, I am not sure why I am getting this error. I am still at the step where I am trying to switch the member statement with consult (From one of the above messages).

> ERROR: d:/my\_project\_path/python/mqi.pl:109:  
> ERROR: source\_sink `library(socket)' does not exist Warning: d:/my_project_path/python/mqi.pl:109: Warning: Goal (directive) failed: mqi:use_module(library(socket)) ERROR: d:/my_project_path/python/mqi.pl:110: ERROR: source_sink `library(http/json)’ does not exist  
> Warning: d:/my\_project\_path/python/mqi.pl:110:  
> Warning: Goal (directive) failed: mqi:use\_module(library(http/json))  
> ERROR: d:/my\_project\_path/python/mqi.pl:111:  
> ERROR: source\_sink `library(http/json_convert)' does not exist Warning: d:/my_project_path/python/mqi.pl:111: Warning: Goal (directive) failed: mqi:use_module(library(http/json_convert)) ERROR: d:/my_project_path/python/mqi.pl:113: ERROR: source_sink `library(term\_to\_json)’ does not exist  
> Warning: d:/my\_project\_path/python/mqi.pl:113:  
> Warning: Goal (directive) failed: mqi:use\_module(library(term\_to\_json))  
> ERROR: d:/my\_project\_path/python/mqi.pl:115:  
> ERROR: source\_sink `library(filesex)' does not exist Warning: d:/my_project_path/python/mqi.pl:115: Warning: Goal (directive) failed: mqi:use_module(library(filesex)) ERROR: d:/my_project_path/python/mqi.pl:121: ERROR: source_sink `library(time)’ does not exist  
> Warning: d:/my\_project\_path/python/mqi.pl:121:  
> Warning: Goal (directive) failed: mqi:use\_module(library(time))  
> ERROR: d:/my\_project\_path/python/mqi.pl:122:  
> ERROR: source\_sink `library(uuid)’ does not exist  
> Warning: d:/my\_project\_path/python/mqi.pl:122:  
> Warning: Goal (directive) failed: mqi:use\_module(library(uuid))  
> ERROR: -g mqi:install\_to\_library(‘./mqi.pl’): mqi:install\_to\_library/1: Unknown procedure: mqi:copy\_file/2

---

<div class="post-metadata">

**Author:** ![ferdasonmez](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ferdasonmez/32/3578_2.png) [@ferdasonmez](https://swi-prolog.discourse.group/u/ferdasonmez)\
**Post date:** [December 6, 2021, 6:01pm UTC](https://swi-prolog.discourse.group/t/setting-up-swiplserver-for-the-first-time-help-needed/4697/18 "2021-12-06T18:01:41Z")

</div>

> [@swi](#):
>
> `swipl --quiet -g mqi_start -t halt -- --write_connection_values=true `

I get the below error ☹

> ERROR: -g mqi\_start: catch/3: Unknown procedure: mqi\_start/0

---

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [December 6, 2021, 6:02pm UTC](https://swi-prolog.discourse.group/t/setting-up-swiplserver-for-the-first-time-help-needed/4697/19 "2021-12-06T18:02:57Z")

</div>

What does

```prolog
swipl --version    

```

return?

---

<div class="post-metadata">

**Author:** ![ferdasonmez](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ferdasonmez/32/3578_2.png) [@ferdasonmez](https://swi-prolog.discourse.group/u/ferdasonmez)\
**Post date:** [December 6, 2021, 6:09pm UTC](https://swi-prolog.discourse.group/t/setting-up-swiplserver-for-the-first-time-help-needed/4697/20 "2021-12-06T18:09:27Z")

</div>

> [@swi](#):
>
> `swipl --version `

SWI-Prolog version 8.3.27 for x64-win64

[Next page](https://swi-prolog.discourse.group/t/setting-up-swiplserver-for-the-first-time-help-needed/4697.md?page=2)
