In this post we will explain how to prepare Machine Learning / Deep Learning / Reinforcement Learning environment in OSX / MacOS.
You can also have a look at version for Ubuntu - HERE
Of course this is only one of the ways to do it - so feel free to experiment.
It consists of :
First it is needed to install Anaconda - python virtual environment management and IDE.
This project has great documentation and you can find all the information HERE.
So first download (from HERE) package for python version 3.6 and execute it.
Once installed we can create our first environment:
conda create -n py35 python=3.5 anaconda
where py35 is the name of environment (you can choose anything you like of course) and important here is to specify python version (in this case 3.5).
We chose this specific version on purpose because OpenAI - as specified on their website - supports python versions 2.7 and 3.5… so we will go with newer one.
After creating environment its time to activate it:
source activate py35
Note! Rest of steps should be executed in activated environment.
And just in case we can check if there are packages to be updated:
conda update --all
Next step is to install Pytorch.
Important to note is that Pytorch stable version 1.1 has been released.
In order to install it - we go to their website where we can find clear instructions. You just need to specify options that you want… in my case:
So final command is:
conda install pytorch torchvision -c pytorch
So now it’s time to install OpenAI gym. This is bit tricky step so we need to be careful.
First as we will be using pip - lets make sure it is in latest version possible (also upgrading 2 other packages)
pip install pip --upgrade
sudo -H pip3 install --upgrade setuptools wheel
And then, following instruction on their github page…
brew install boost-python3
brew install cmake boost sdl2 swig wget
And, before gym installation, we need to deal with its dependency - mujoco-py..
(for mujoco we need to make sure that cython is newer version as well - hence first step below is important)
pip install --upgrade cython
git clone https://github.com/openai/mujoco-py
pip install -e ./mujoco-py/
And now we’re ready to do gym installation!
I found out that here - it is good idea to export this variable:
Of course value depends on version of your system so you have to check it on your own (for example in About This Mac) …
Finally we can execute command to install Gym
pip install 'gym[all]'
It installs quite a long list of packages, but amongst the other there is also newest pyglet version, which based on my observations (and well info found HERE ) we need to downgrade… in order to avoid some rendering problems later.
pip install pyglet==1.2.4
For the same reason (rendering problem) we also changed configuration of matplotlib..
It shows location of matplotlib configuration file … in my case:
We edit the file and change backend setting to :
backend : Agg
With those 2 steps - we realized that rendering doesn’t cause any problems.
Additionally if you want record videos in gym it is good idea to install ffmpeg via brew (and uninstall - if you have it - from conda)
conda remove ffmpeg
brew install ffmpeg --with-fdk-aac --with-sdl2 --with-freetype --with-libass --with-libquvi --with-libvorbis --with-libvpx --with-opus --with-x265
UPDATE - to be confirmed! It seems that finally installation of ffmpeg has been simplified and it is enough to execute:
brew install ffmpeg
So now - finally! - we can verify if everything is OK.
While installing Anaconda (in one first steps) we also installed Spyder - IDE for python. Of course use your favourite one but here in case of Spyder (executed via Anaconda-Navigator)…
we need to make sure that we chose proper environment (of course with the name as created before)
then execute it…
And now we can verify if everything works fine
If we have no errors on above steps - it means we’re OK and we’ve successfully installed our environment!
Depending on your requirements and (or) needs you probably might be interested in installing Tensorflow as well.
pip install tensorflow
And to verify:
python -c 'import tensorflow as tf; print(tf.__version__)'