I’m trying to load a Python module from a directory added to the Python module search path with py_add_lib_dir/1
and failing. The module search path seems to be recognised but the file is still not found.
The below code and output shows how I’m trying to add the new Python module search path and then use it, and the resulting error:
% Directive adding module_path to Python module search path.
:- py_add_lib_dir(model_data).
% Part of program calling the Python module under the new search path.
% This is in the same Prolog module as the directive adding the search path.
environment_init(E,[Sim|Fs],q0,O0,[Sim|Gs]):-
...
,py_call(basic_sim:init_sim(agent_start=[Xpv,Ypv]),Sim)
...
% Checking that the module search path is correctly added; it's the first one:
?- py_lib_dirs(_Ds), maplist(writeln,_Ds).
c:/users/yegoblynqueenne/documents/prolog/ilp_systems/louise/data/bath/model/data/model_data
c:/program files/swipl/library/ext/swipy/python
c:/program files/python310/python310.zip
c:/Program Files/Python310/Lib
c:/Program Files/Python310/DLLs
c:/Program Files/swipl/bin
c:/Users/YeGoblynQueenne/AppData/Roaming/Python/Python310/site-packages
c:/Program Files/Python310
c:/Program Files/Python310/lib/site-packages
c:/Program Files/Python310/lib/site-packages/vboxapi-1.0-py3.10.egg
true.
% Call to environment_init/5 that raises an error:
?- basic_sim_grid:environment_init('Episode0',Fs,Q0,O0,Gs).
ERROR: Python 'ModuleNotFoundError':
ERROR: No module named 'basic_sim'
ERROR: In:
ERROR: [13] janus:py_call(basic_sim:init_sim(...),_17572)
ERROR: [12] basic_sim_grid:environment_init('Episode0',[_17624,...|...],q0,_17618,[_17636,...|...]) at c:/users/yegoblynqueenne/documents/prolog/ilp_systems/louise/data/bath/model/data/basic_sim_grid_environment.pl:32
ERROR: [11] toplevel_call(user:basic_sim_grid: ...) at c:/program files/swipl/boot/toplevel.pl:1318
^ Exception: (4) setup_call_cleanup('$toplevel':notrace(call_repl_loop_hook(begin, 0)), '$toplevel':'$query_loop'(0), '$toplevel':notrace(call_repl_loop_hook(end, 0))) ? abort
% Execution Aborted
If I move the Python file I’m trying to load (basic_sim.py
) to the same directory as the running Prolog process, it is loaded without error.
So it looks like the new Python module search path is ignored, even though it is reported by py_lib_dirs/1
.
I’m on SWI-Prolog 9.3.8-27-g80f956be2 64 bits.