# Prolog 8.3.2 GUI can not find \[likes\] source file

**URL:** <https://swi-prolog.discourse.group/t/prolog-8-3-2-gui-can-not-find-likes-source-file/2542>\
**Category:** Installing\
**Created:** [June 20, 2020, 4:06am UTC](https://swi-prolog.discourse.group/t/prolog-8-3-2-gui-can-not-find-likes-source-file/2542 "2020-06-20T04:06:03Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![santisuk](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/santisuk/32/1668_2.png) [@santisuk](https://swi-prolog.discourse.group/u/santisuk)\
**Post date:** [June 20, 2020, 4:06am UTC](https://swi-prolog.discourse.group/t/prolog-8-3-2-gui-can-not-find-likes-source-file/2542/1 "2020-06-20T04:06:03Z")

</div>

Hello, I’m very new to Prolog. I installed SWI-Prolog 8.3.2 for Windows 32 bits without any installation options changed from defaults. Installation is completed. I run program by click on SWI-Prolog icon on Windows Start menu. I try to load likes.pl as described in Tutorials from [https://www.swi-prolog.org/pldoc/man?section=quickstart](https://www.swi-prolog.org/pldoc/man?section=quickstart). It seems prolog can not find likes.pl and show error messages.

 ![SWI-PL-Likes](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/2X/2/2b31dfd1368e24c9f784e37f2cb8c1de91ddce3c.png)

What can I do to solve this problem ?

However, If I run SWI-Prolog (Console) version. It can find and load likes.pl without any errors.

Thank you.

---

<div class="post-metadata">

**Author:** ![JCR](https://avatars.discourse-cdn.com/v4/letter/j/258eb7/32.png) [@JCR](https://swi-prolog.discourse.group/u/JCR)\
**Post date:** [June 20, 2020, 8:03am UTC](https://swi-prolog.discourse.group/t/prolog-8-3-2-gui-can-not-find-likes-source-file/2542/2 "2020-06-20T08:03:08Z")

</div>

I think that you have to provide the complete directory specification within square braces (which is a shortcut for the consult command). As an alternative you can load the file by going to the File menu and choose Consult.  
Cheers/JC

---

<div class="post-metadata">

**Author:** ![santisuk](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/santisuk/32/1668_2.png) [@santisuk](https://swi-prolog.discourse.group/u/santisuk)\
**Post date:** [June 20, 2020, 9:16am UTC](https://swi-prolog.discourse.group/t/prolog-8-3-2-gui-can-not-find-likes-source-file/2542/3 "2020-06-20T09:16:48Z")

</div>

Thanks for your reply. I test your suggestion by type [“c:/Program Files/swipl/demo/likes”]. It works by replies “true.”.

But Console version work fine just type [likes], Does it mean, by default, swipl\_win.exe and swipl.exe have different directory for configuration ? and How can I know what is that directory.

---

<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:** [June 20, 2020, 9:46am UTC](https://swi-prolog.discourse.group/t/prolog-8-3-2-gui-can-not-find-likes-source-file/2542/4 "2020-06-20T09:46:06Z")

</div>

> [@santisuk](#):
>
> and How can I know what is that directory

When you run `swipl_win` or `swipl` try this:

```prolog
?- pwd.
%<it will print directory here>

```

---

<div class="post-metadata">

**Author:** ![santisuk](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/santisuk/32/1668_2.png) [@santisuk](https://swi-prolog.discourse.group/u/santisuk)\
**Post date:** [June 20, 2020, 10:55am UTC](https://swi-prolog.discourse.group/t/prolog-8-3-2-gui-can-not-find-likes-source-file/2542/5 "2020-06-20T10:55:20Z")

</div>

In Console version, It is `% c:/program files/swipl/`

In GUI version, It is `% c:/users/sam/documents/prolog/` (_sam_ is user name.) And after I changed directory by type `cd("c:/program files/swipl/").` Type `[likes].` can work now. 😃 Thank you.

This guide me next question, How to auto config default directory since start swipl\_win.exe ?

---

<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:** [June 20, 2020, 12:39pm UTC](https://swi-prolog.discourse.group/t/prolog-8-3-2-gui-can-not-find-likes-source-file/2542/6 "2020-06-20T12:39:43Z")

</div>

> [@santisuk](#):
>
> How to auto config default directory since start swipl\_win.exe ?

While that is actually a valid next question IMHO it is the wrong next question to ask. The reason is that if you want to do more than just simple learning with Prolog you will start to do many different projects. If all of those projects are in the same directory it can cause problems down the road.

As I primarily use SWI-Prolog on Windows here are some of the things that will help you.

1. The directory `swipl` is started from becomes the working directory.

```prolog
C:\Users\Eric>swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.0-172-g5e86d749d)
...
1 ?- pwd.
% c:/users/eric/
true.

2 ?- halt.

C:\Users\Eric>cd documents\prolog

C:\Users\Eric\Documents\Prolog>swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.0-172-g5e86d749d)
...
1 ?- pwd
.
% c:/users/eric/documents/prolog/
true.

```

1. Use working\_directory/2 to change the working directory with in SWI-Prolog.

```prolog
C:\Users\Eric>swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.0-172-g5e86d749d)
...
1 ?- working_directory(D,D).
D = 'c:/users/eric/'.

2 ?- working_directory(D,'c:/users/eric/documents/prolog').
D = 'c:/users/eric/'.

3 ?- pwd.
% c:/users/eric/documents/prolog/
true.

4 ?- working_directory(D,D).
D = 'c:/users/eric/documents/prolog/'.

5 ?-

```

1. Prolog source code is loaded using consult/1, or `[]`. See: [Getting started quickly](https://www.swi-prolog.org/man/quickstart.html)

Note: Prolog expects path separators as `/` and not `\` as Windows uses.

```prolog
C:\Users\Eric>swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.0-172-g5e86d749d)
...
1 ?- pwd.
% c:/users/eric/
true.

2 ?- consult('C:/Users/Eric/Documents/Projects/Prolog/simple_test.pl').
true.

3 ?- ['C:/Users/Eric/Documents/Projects/Prolog/simple_test.pl'].
true.

4 ?- consult('C:\Users\Eric\Documents\Projects\Prolog\simple_test.pl').
ERROR: Syntax error: Illegal \u or \U sequence
ERROR: consult('C:
ERROR: **here**
ERROR: \Users\Eric\Documents\Projects\Prolog\simple_test.pl') .
4 ?-

```

1. If consult/1 is given a relative path it will use the working directory.

```prolog
Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.0-172-g5e86d749d)
...
1 ?- pwd.
% c:/users/eric/documents/projects/prolog/
true.

2 ?- consult('simple_test.pl').
true.

3 ?- ['simple_test.pl'].
true.

```

1. working\_directory/2 can be put in a [directive](https://www.swi-prolog.org/pldoc/man?section=consulting) so it is executed when the source code is loaded. This can be used to change the working directory automatically each time the source code is loaded. This is useful if the code is doing I/O to files and the file location is static and known ahead of time, e.g. developing with [library(persistency)](https://www.swi-prolog.org/pldoc/man?section=persistency).

File: `C:/Users/Eric/Documents/Projects/Prolog/swi-discourse_046.pl`

```prolog
:- working_directory(_,'C:\\Users\\Eric\\Documents\\Projects\\Prolog').

```

```prolog
Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.0-172-g5e86d749d)
...
?- working_directory(D,D).
D = 'c:/users/eric/documents/prolog/'.

?- consult("C:/Users/Eric/Documents/Projects/Prolog/swi-discourse_046.pl").
true.

?- working_directory(D,D).
D = 'c:/users/eric/documents/projects/prolog/'.

```

* * *

* * *

How I quickly get started with my projects

I use [Visual Studio Code](https://code.visualstudio.com/) as my primary editor.

When working with projects I start by editing the Prolog source code in the editor and at the top of the source I add a section like the following that sets the working directory for Prolog when the code is consulted by SWI-Prolog, e.g.

```prolog
% -----------------------------------------------------------------------------

% DELETE THIS SECTION BEFORE POSTING

:- if(current_prolog_flag(windows,true)).
:- working_directory(_,'C:/Users/Eric/Documents/Projects/SWI-Prolog/SO_question_100').
:- elif(current_prolog_flag(unix,true)).
:- working_directory(_,'/mnt/c/Users/Eric/Documents/Projects/SWI-Prolog/SO_question_100').
:- endif.

% [SO_question_100].

% ----------------------------------------------------------------------------

```

The comment includes changing the directory in both a Windows flavor and a Linux flavor as I occasionally switch to working with code on Linux via WSL 2 running a Linux distro.

One common [mistake](https://swi-prolog.discourse.group/t/unknown-procedure-module-2/2778) I started to make when using the above was that I would put the module definition after the comment, the module definition has to be the first line of Prolog code, e.g.

```prolog
:- module(SO_question_100,[]).

% -----------------------------------------------------------------------------

% DELETE THIS SECTION BEFORE POSTING
...
% ----------------------------------------------------------------------------

```

Since the projects start by opening Visual Studio Code and Visual Studio Code keeps track of projects, by right clicking on the Visual Studio Code icon in the Windows task bar

 ![image](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/2X/4/4d4c2338f542c95e8b5459608863daa4e4b590d8.jpeg)

I can quickly select either a simple project as a single file or a larger project as a folder which starts Visual Studio Code, loads the files or directories and files and then opens the files where they were last left. At the top of the main source code file is a consult comment which I copy and paste into SWI-Prolog once I start it.

With Visual Studio Code I mainly use two plugins for Prolog source code editing. ([ref](https://swi-prolog.discourse.group/t/ide-editor-for-swi-prolog/584/7))

* * *

Bonus section.

If you start to use SWI-Prolog often and work on Windows you will eventually find that also working with SWI-Prolog on Linux is desired. Take a look at [WSL 2](https://docs.microsoft.com/en-us/windows/wsl/wsl2-index) as this will allow you to work with Linux and Windows on the same machine at the same time and share the files on both OS at the same time. Files on Linux can be seen with File Explorer and files on Windows can be seen from Linux as a mount. WSL 2 offers so much more than just file sharing, you can even start an X windows session in Windows and do the work in Linux while keeping the files on Windows.

---

<div class="post-metadata">

**Author:** ![emacstheviking](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/emacstheviking/32/228_2.png) [@emacstheviking](https://swi-prolog.discourse.group/u/emacstheviking)\
**Post date:** [June 20, 2020, 1:52pm UTC](https://swi-prolog.discourse.group/t/prolog-8-3-2-gui-can-not-find-likes-source-file/2542/7 "2020-06-20T13:52:35Z")

</div>

best reply ever

---

<div class="post-metadata">

**Author:** ![CapelliC](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/capellic/32/17_2.png) [@CapelliC](https://swi-prolog.discourse.group/u/CapelliC)\
**Post date:** [June 20, 2020, 2:00pm UTC](https://swi-prolog.discourse.group/t/prolog-8-3-2-gui-can-not-find-likes-source-file/2542/8 "2020-06-20T14:00:05Z")

</div>

You can use the [Settings / USer init file…] menu.  
Beware that the editor window could be rather slow to open, and it probably will issue  
a message box, asking for creation of the the init.pl in the appropriate folder - the path changed recently - that could be hidden behind - for instance - a full screen browser window.

When you have the init.pl file open - presumably blank - you can set an initialization path be means of a directive, like

```prolog
:- cd('C:\\Users\\Carlo\\tex2swi').
:- maplist(edit, ['tex2swi.pl','gen_swinb.pl','parse_tex.pl','tex2swi.plt']).

```

Next time you will start Prolog it will attempt to change to such directory.  
You can put in your init.pl a lot of utilities, for instance it’s not difficult to reload a bunch of files - your preferred ‘workspace’, as you can see above.

---

<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:** [June 20, 2020, 2:05pm UTC](https://swi-prolog.discourse.group/t/prolog-8-3-2-gui-can-not-find-likes-source-file/2542/9 "2020-06-20T14:05:50Z")

</div>

One way to avoid depending on the working directory for loading `likes.pl` is this

```
?- [swi(demo/likes)].

```

If you want to change the start dir, I guess the best is to edit the Windows shortcut. Remove `--win-app`, which clauses the system to create `prolog` in the standard document folder and go there. Next set the start folder as you please.

Once upon a time you could double click a `*.pl` file to open it in Prolog (and Prolog would go to the directory of this file). I don’t know whether this still works. Don’t have a Windows machine around … What should work is to drop a `*.pl` files onto the Prolog desktop shortcut.

---

<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:** [June 20, 2020, 2:56pm UTC](https://swi-prolog.discourse.group/t/prolog-8-3-2-gui-can-not-find-likes-source-file/2542/10 "2020-06-20T14:56:34Z")

</div>

> [@jan](#):
>
> One way to avoid depending on the working directory for loading `likes.pl` is this
> 
> ```prolog
> ?- [swi(demo/likes)].
> 
> ```

This works on Windows 10

```prolog
Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.0-172-g5e86d749d)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- [swi(demo/likes)].
true.

?- listing(likes).
likes(sam, Food) :-
    indian(Food),
    mild(Food).
likes(sam, Food) :-
    chinese(Food).
likes(sam, Food) :-
    italian(Food).
likes(sam, chips).

true.

?- likes(sam,Food).
Food = dahl ;
Food = tandoori ;
Food = kurma ;
Food = chow_mein ;
Food = chop_suey ;
Food = sweet_and_sour ;
Food = pizza ;
Food = spaghetti ;
Food = chips.

?- pwd.
% c:/users/eric/documents/prolog/
true.

?- working_directory(D,D).
D = 'c:/users/eric/documents/prolog/'.

```

Notice that the working directory is different than the location for likes, i.e. `C:\Program Files\swipl\demo\likes.pl`

* * *

* * *

> [@jan](#):
>
> Once upon a time you could double click a `*.pl` file to open it in Prolog (and Prolog would go to the directory of this file).

On my Windows 10 system is

`C:\Users\Eric\Documents\Projects\Prolog\swi-discourse_045.pl`

```prolog
% consult("C:/Users/Eric/Documents/Projects/Prolog/swi-discourse_045.pl").

% https://swi-prolog.discourse.group/t/prolog-8-3-2-gui-can-not-find-likes-source-file/2542

% -----------------------------------------------------------------------------

test :-
    format('~w World!',['Hello,']).

```

Double clicking the file in File Explorer

![image](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/2X/a/abf9bf9ca85ec0b5516ec676d27b01ed96f7c8b0.png)

Running test without fist using consult because the file was consulted via the double click action.

```prolog
?- test.
Hello, World!
true.

```

Notice the title of the window is `SWI-Prolog -- c:/Users/Eric/Documents/Projects/Prolog/swi-discourse_045.pl`

Notice that in File Explorer when the file association `.pl` file type is set to SWI-Prolog the `.pl` files will have an SWI-Prolog icon, i.e. ![image](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/2X/a/a8024ad54a80b7b4e963e11946c5c296a1ed016e.png)

* * *

This occurs because I have the file association for `.pl` set to `C:\Program Files\swipl\bin\swipl-win.exe`

See: [Set or Change File Associations & Extensions in Windows 10](https://www.thewindowsclub.com/change-file-associations-windows/#:~:text=To%20set%20File%20Associations%20in,Description%20and%20the%20Current%20Default.)

* * *

* * *

> [@jan](#):
>
> What should work is to drop a `*.pl` files onto the Prolog desktop shortcut.

Dropping a SWI-Prolog source code file on to the SWI-Prolog desktop shortcut works in Windows and will consult the source code and set the working directory.

The easiest way to create a desktop shout cut is to use File Explorer to find the SWI-Prolog executable `C:\Program Files\swipl\bin\swipl-win.exe` then right click and drag and drop it onto the desktop and select `Create Shortcut here`.

---

<div class="post-metadata">

**Author:** ![stassa.p](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/stassa.p/32/712_2.png) [@stassa.p](https://swi-prolog.discourse.group/u/stassa.p)\
**Post date:** [June 22, 2020, 12:49pm UTC](https://swi-prolog.discourse.group/t/prolog-8-3-2-gui-can-not-find-likes-source-file/2542/11 "2020-06-22T12:49:13Z")

</div>

> [@jan](#):
>
> Once upon a time you could double click a `*.pl` file to open it in Prolog (and Prolog would go to the directory of this file). I don’t know whether this still works

That totally works still for me (I’m on windows 10 like @EricGT). I hope it doesn’t change in the future because it’s very useful. For example, I have a project load file in all my projects that a) starts the documentation browser, b) opens select project files in the IDE and c) consults the project’s “entry point” file. That way I can start working on a project by double-clicking the load file (or navigating to the load file by keyboard and pressing enter, to protect my wrists).

Please don’t change this 🙂

(I think this works on linux also, except of course if you consult the load file from a terminal it will open your default editor _in the terminal_. Which can be confusing if the project load file attempts to open multiple source files at once, especially if your default editor doesn’t have tabs. Should be even more fun when the default editor is the default editor) (ed).
