Prolog process_create problem

Hello,

I’m using: SWI-Prolog version 8.0.3

I want the code to be able to calculate results using libraries like numpy and scipy in Python and pass those results to Prolog

But what I’m getting is:
an empty String after I import numpy in the Python script.

My code looks like this:

%prolog%
do() :-process_create(path(python),['U:\\PythonCode\\dummyImport.py' ],
                    [stdout(pipe(In))]),
    read_string(In, Len, X),write(Len:X).
_________________________________________________________________________________

%python%
import numpy as np
result  = 3*np.cos(42)-333*np.sin(42)

print (str(result))

What do I do wrong?

1 Like

Seems you are using Windows. If you use the swipl-win.exe console, process output to stderr is lost. I would also connect that to a pipe and read it. That might give a hint on what is wrong.

For a demo, that is good enough. For real code code you must close the streams and if you read both output and error you need to read them in different threads to avoid that the process suspends because you are not reading its output. library(git) gives some more elaborate wrappers around the (git) process.

3 Likes

Thank you for your advise!
I’ve read the stderr output & found the bug.
There was a path missing for the Anaconda Library in my Windows 10 path variables.