Why can't I import the Stable Baselines 3 module in CoppeliaSim using Python?

Typically: "How do I... ", "How can I... " questions
Post Reply
ly_glez
Posts: 2
Joined: 31 Mar 2022, 17:34

Why can't I import the Stable Baselines 3 module in CoppeliaSim using Python?

Post by ly_glez »

I'm trying to test some of the Stable Baselines 3 Deep Reinforcement Learning algorithms in CoppeliaSim version 4.3.0 (the one that lets you create scripts in Python). I can import other modules such as numpy, gym and torch without errors. However, when I do the following import, I get an error and the simulation crashes:

Code: Select all

from stable_baselines3 import PPO
This is the error I get:

Code: Select all

[/robot@childScript:error] ...es/CoppeliaRobotics/CoppeliaSimEdu/lua/pythonWrapper.lua:334: The Python interpreter could not handle the wrapper script (or communication between the launched subprocess and CoppeliaSim could not be established via sockets). Make sure that the Python modules 'cbor' and 'zmq' are properly installed, e.g. via:
$ /path/to/python -m pip install pyzmq
$ /path/to/python -m pip install cbor
stack traceback:
    [C]: in function 'error'
    ...es/CoppeliaRobotics/CoppeliaSimEdu/lua/pythonWrapper.lua:334: in function 'initPython'
    ...es/CoppeliaRobotics/CoppeliaSimEdu/lua/pythonWrapper.lua:225: in function 'sysCall_init'
I have already installed the cbor and zmq modules. I installed the Stable Baselines 3 package using the following command:

Code: Select all

pip install stable-baselines3[extra]
I added the following code below the #python comment at the beginning of the script, but it didn't solve my problem.

Code: Select all

#luaExec additionalIncludePaths={'C:/Python310/Lib/site-packages'}
I run my Python code in Visual Studio Code and it imports the Stable Baselines 3 module and works perfectly.

I don't know what else to do. Please, help.
coppelia
Site Admin
Posts: 10747
Joined: 14 Dec 2012, 00:25

Re: Why can't I import the Stable Baselines 3 module in CoppeliaSim using Python?

Post by coppelia »

Hello,

the baselines 3 module is quite heavy and takes a few seconds to load. You should adjust the timeout in <coppeliaSimFolder>/lua/pythonWrapper.lua, around line 293, from:

Code: Select all

while sim.getSystemTimeInMs(st)<2000 do
to e.g.:

Code: Select all

while sim.getSystemTimeInMs(st)<10000 do
Above should not be needed anymore with CoppeliaSim V4.6 and later

Cheers
ly_glez
Posts: 2
Joined: 31 Mar 2022, 17:34

Re: Why can't I import the Stable Baselines 3 module in CoppeliaSim using Python?

Post by ly_glez »

coppelia wrote: 07 Apr 2022, 13:43 Hello,

the baselines 3 module is quite heavy and takes a few seconds to load. You should adjust the timeout in <coppeliaSimFolder>/lua/pythonWrapper.lua, around line 293, from:

Code: Select all

while sim.getSystemTimeInMs(st)<2000 do
to e.g.:

Code: Select all

while sim.getSystemTimeInMs(st)<10000 do
Cheers
Your solution did the trick! Thank you very much.
Post Reply