Reinforcement Learning with OpenAI Gym and Roboschool: Install Roboschool in Mac
Published on 29 Nov 2017
## Installations Installing OpenAI `roboschool` turned out to be one of the most hectic installations I ever did. Here are the steps I followed to install [roboschool](https://github.com/openai/roboschool) inside a conda enviroment in my macbook. It is recommended to use *python3 * even though python2 may also work. #### Step1: Create a conda environment In the mac os python3.6 gave a segmentation fault when importing roboschool after all the installation. So following the advice [here](https://github.com/openai/roboschool/issues/79) python 3.5.2 works fine. conda create -n robo-env python=3.5.2 source activate robo-env #### Step2: Install gym Clone the [gym repo](https://github.com/openai/gym) to a local folder, cd to that folder and install. Make sure to install the dependencies first. brew install cmake boost boost-python sdl2 swig wget git clone https://github.com/openai/gym cd gym pip install -e . #### Step3: Clone both roboschool and bullet3 First clone the [roboschool repo](https://github.com/openai/roboschool) to a local folder. Now cd to that folder and clone the [bullet3](https://github.com/olegklimov/bullet3). It is very important that bullet3 is under roboschool folder. (This is not very clear in the original installation instructions and got me frustrated for a long time). git clone https://github.com/openai/roboschool cd roboschool ROBOSCHOOL_PATH=`pwd` git clone https://github.com/olegklimov/bullet3 -b roboschool_self_collision cd bullet3 mkdir build cd build cmake -DBUILD_SHARED_LIBS=ON -DUSE_DOUBLE_PRECISION=1 -DCMAKE_INSTALL_PREFIX:PATH=$ROBOSCHOOL_PATH/roboschool/cpp-household/bullet_local_install -DBUILD_CPU_DEMOS=OFF -DBUILD_BULLET2_DEMOS=OFF -DBUILD_EXTRAS=OFF -DBUILD_UNIT_TESTS=OFF -DBUILD_CLSOCKET=OFF -DBUILD_ENET=OFF -DBUILD_OPENGL3_DEMOS=OFF .. make -j4 make install cd ../.. #### Step4: Install Roboschool In step3 we built the bullet3 source files which are required for the roboschool installation which has been copied to the roboschool/roboschool/cpp-household/bullet_local_install folder. Now do some more dependency software installations brew install cmake tinyxml assimp ffmpeg brew install boost-python --without-python --with-python3 --build-from-source brew install qt Now we are ready to install. But before that set the pkg config path export PKG_CONFIG_PATH=$(dirname $(dirname $(which python)))/lib/pkgconfig Now the `pkg-config --cflags python-3.5` should show you the local python include directory. Also `pkg-config --cflags Qt5Widgets Qt5OpenGL` should show the homebrew installation paths of Qt. Now I had to make some changes to the ***Makefile*** inside roboschoo/cpp-household. Before that let's try our luck at installing roboschool. Make sure you are currently in the roboschool root directory ($ROBOSCHOOL_PATH). python setup.py install #(pip install -e . is also fine) Unfortunately I got the error that `` file was not found. Later I figured out that the Makfile doesn't point correctly to the OpenGL directory. To fix this make sure the Makefile has the correct include directory under darwin os. INC =-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/usr/local/include I had to make a few more changes to the Makefile. Set the moc bin directory manually and set the library path to boost-python. Here is a snapshot from the Makefile ifeq ($(UNAME),Darwin) # ifneq ("$(wildcard /usr/local/opt/qt5/bin/moc"), "") # $(info Mac, assumed python3, homebrew branch) # MOC =/usr/local/opt/qt5/bin/moc # else $(info Mac, assumed python3, anaconda branch) MOC = /usr/local/bin/moc #endif PKG =pkg-config LIBS =-framework OpenGL INC =-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/usr/local/include BOOST_PYTHON3_POSTFIX = 3 BOOST_PYTHON3_POSTFIX = 3 BOOST_MT=-mt PYTHON = $(shell python3 -c "import sys; print('%i.%i' % sys.version_info[:2])") RPATH = endif Set the correct path to boost-python as well. ifeq ($(PYTHON),2.7) BOOST_PYTHON = -lboost_python else BOOST_PYTHON = -L/usr/local/Cellar/boost-python/1.65.1/lib -lboost_python3 endif Finally `python setup.py install` should install roboschool sucessfully. Hopefully `python -c "import roboschool"` don't cause any segmentation fault. Finally if we are lucky, test running an example code should give you the awesome roboschool running. `python agent_zoo/RoboschoolHumanoidFlagrun_v0_2017may.py` ![robo-soccer](https://dl.dropboxusercontent.com/s/ploxzn14kuw7u3n/roboschool.png)