How can I import `gym` module? or install?

To whom it may concern.

Hello, your courses are very helpful to my works and I’m trying to realize it on my local PC.

I hope this message would not bother you.

I’ve succeeded in installing openai_ros, but I can’t import the gym module.

So I additionally installed gym-gazebo module, but it also didn’t work.

I eventually install gym of openai, and it can import gym module.

Now the only problem is that it is only allowed to do that in gym directory; it brings up ImportError.

What I want to ask is that how can I make the same setup as your simulation wrt openai_ros and gym.

Would it be ok if I install openai_ros and gym?
Did I install the correct modules to implement DQL?
Would you please let me know what should I install?

Just so you know, the simulation setups you provide are not compatible with my PC, so I’ve made my own setups following yours and tried the tutorials. But in the case of DRL, I can’t import gym…in my local PC environment.

Thanks in advance :slight_smile:

Hi @dkfkgks1218cf7a77dc90654b63,
to install gym in Linux, simply run these commands:

sudo apt install python-pip
pip install gym

Thanks for your quick reply.

So, your commands allows to use gym module in with openai_ros package ROS Deep-Learning?

I’ll try them soon. :slight_smile:

Yes, pip is a sort of python package manager, which makes it very easy to install missing python libraries or packages. Once gym is installed, you can use it anywhere with python, including openai_ros.

Only installing pip only and the openai_ros package will not do it. You also need to create a Python3 virtual environment in order to make work the Python3 libraries of OpenAI with the ROS packages.

If you want to learn how to do that, check the Live Class we did yesterday which teaches how to do that exactly. It also uses the example of using OpenAI + openai_ros to train a robot.

You can check the Live Class at the Robot Ignite Academy section of Live Classes (there you will also find the rosject with the code) or you can go to the Youtube video recorded here

A post was split to a new topic: Where’s Live Class #81?

Thanks for your kind reply. To get a virtual Python 3 environment, the following two commands:

$ apt-get install -y python3-venv
$ pyvenv venv1

allow me to do that, as far as I know.

And this is what I suddenly thought of: is it also possible to install PyTorch in that python 3 virtual environment?

And one more, if it is not impossible, can I use ROS, Gazebo and any other ROS packages which have been run in python 2.7 environment at the same time?

I really hope this message would not bother your work…
But I’d like to use it if I can do the above things :disappointed_relieved:

Thanks in advance :slight_smile:

You can use pytorch or any other python3 library you want or need for Reinforcement Learning or deep learning in the python3 environment. However, running ROS in the python3 environment requires a lot of custom compiling, troubleshooting and headache.

I recommend using the Pyro4 library to communicate between the python3 gym environment and the python2 ROS environment.

I tried the command following Live Class #81, but in the step of for compiling the packages with Python3,

$ catkin_make -DPYTHON_EXECUTABLE:FILEPATH=/home/user/python3_ws/py3venv/bin/python

I always get the error messages:

– Using CATKIN_DEVEL_PREFIX: /home/beomsoo/python3_ws/devel
– Using CMAKE_PREFIX_PATH: /home/beomsoo/catkin_ws/devel;/opt/ros/kinetic
– This workspace overlays: /home/beomsoo/catkin_ws/devel;/opt/ros/kinetic
CMake Error at /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find PythonInterp: Found unsuitable version “1.4”, but required
is at least “2” (found /home/user/python3_ws/py3venv/bin/python)
Call Stack (most recent call first):
/usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:386 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.5/Modules/FindPythonInterp.cmake:163 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
/opt/ros/kinetic/share/catkin/cmake/python.cmake:4 (find_package)
/opt/ros/kinetic/share/catkin/cmake/all.cmake:164 (include)
/opt/ros/kinetic/share/catkin/cmake/catkinConfig.cmake:20 (include)
CMakeLists.txt:56 (find_package)

– Configuring incomplete, errors occurred!
See also “/home/beomsoo/python3_ws/build/CMakeFiles/CMakeOutput.log”.
Invoking “cmake” failed

I know I’m quite rude already, but would you please let me know how to troubleshoot this kind of error?
Thanks inadvance.

Sorry for my rudeness and I really hope this message would not bother you.

However, I’m still suffered from the environment of python3 for the ‘openai_ros’;
I’ve failed to compile in python3 env.

It seems you are rather familiar with openai_ros and gym on Gazebo and ROS.

Is it necessary to set python 3 to use openai_ros and gym?

What I want to do is Deep Reinforcement Learning with openai_ros and gym.

I can these already:

import openai_ros
import gym

in my codes.

And just so you know, it’s ok I can’t run it by roslaunch command; I’m planning to do it by python files.py command.

Thanks in advance.