最近一位外国友人在复现某个项目的代码时环境配置出了些问题,找我帮忙解决。说实话,游戏和增强学习这两方面我都不是很熟悉,但好在对 Ubuntu 还算熟悉,前前后后折腾了好久,终于让程序顺利运行了起来。不得不说,这些深度学习的环境配置起来真是让人心烦,各种库的版本层出不穷,一着不慎满盘皆输,但我们又能怎么办呢,只能硬着头皮冲鸭!
项目地址戳此——Minecraft-Reinforcement-Learning
安装环境
Ubuntu 16.04
Python 3.6
malmo0.34.0
gym0.7.4
minecraft-py0.0.2
gym-minecraft0.0.2
pygame==1.9.4.dev0
1. 安装 Malmo 和相关依赖库
wget https://github.com/Microsoft/malmo/releases/download/0.34.0/Malmo-0.34.0-Linux-Ubuntu-16.04-64bit_withBoost_Python3.5.zip
unzip Malmo-0.34.0-Linux-Ubuntu-16.04-64bit_withBoost_Python3.5.zip
mv Malmo-0.34.0-Linux-Ubuntu-16.04-64bit_withBoost_Python3.5 Malmo
cp -r Malmo ~ # 移动文件夹到任意位置即可
sudo apt-get install libboost-all-dev libpython2.7 openjdk-8-jdk lua5.1 libxerces-c3.1 liblua5.1-0-dev ffmpeg python-tk python-imaging-tk
sudo update-ca-certificates -f
2. 安装 OpenAI gym
whereis pip
> pip: /usr/local/bin/pip2.7 /usr/local/bin/pip3.6 /usr/local/bin/pip /home/lab/anaconda3/bin/pip3.6 /home/lab/anaconda3/bin/pip /usr/share/man/man1/pip.1.gz
sudo /usr/local/bin/pip3.6 install gym==0.7.4
- 如果有多个版本的 pip,需要指定具体路径,然后安装 gym 0.7.4
3. 安装 minecraft_py
git clone https://github.com/tambetm/minecraft-py.git
cd minecraft-py
cp -r ../Malmo/Minecraft/ minecraft_py/Malmo
cp -r ../Malmo/Mod/ minecraft_py/Malmo
cp -r ../Malmo/Python_Examples/ minecraft_py/Malmo
cp -r ../Malmo/Schemas/ minecraft_py/Malmo/
# 复制第一步 Malmo 文件夹下的 Minecraft、Mod、Python_Examples 和 Schemas 到 minecraft_py/Malmo 下
sudo /usr/bin/python3.6 setup.py install
- 若直接安装会报以下错误
warning: no directories found matching 'minecraft_py/Malmo/Minecraft'
warning: no directories found matching 'minecraft_py/Malmo/Mod'
warning: no directories found matching 'minecraft_py/Malmo/Python_Examples'
warning: no directories found matching 'minecraft_py/Malmo/Schemas'
4. 安装 gym-minecraft
cd ..
git clone https://github.com/tambetm/gym-minecraft.git
cd gym-minecraft
sudo /usr/bin/python3.6 setup.py install
5. 安装 Pygame
sudo apt-get install mercurial python3-dev python3-setuptools python3-numpy python3-opengl
libav-tools libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsmpeg-dev
libsdl1.2-dev libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev
libtiff5-dev libx11-6 libx11-dev fluid-soundfont-gm timgm6mb-soundfont
xfonts-base xfonts-100dpi xfonts-75dpi xfonts-cyrillic fontconfig fonts-freefont-ttf
cd ..
hg clone https://bitbucket.org/pygame/pygame
cd pygame
sudo /usr/bin/python3.6 setup.py build
sudo /usr/bin/python3.6 setup.py install
6. 添加 ScoreBoard 到 Gym
wget https://github.com/openai/gym/archive/v0.7.4.zip
unzip v0.7.4.zip
sudo cp -r gym-0.7.4/gym/scoreboard /usr/local/lib/python3.6/dist-packages/gym/
7. 添加环境变量
echo "export MALMO_XSD_PATH=/usr/local/lib/python3.6/dist-packages/minecraft_py-0.0.2-py3.6.egg/minecraft_py/Malmo/Schemas" >> ~/.bashrc
source ~/.bashrc
8. 一些问题
- 此时,可以先尝试运行
/usr/local/lib/python3.6/dist-packages/minecraft_py-0.0.2-py3.6.egg/minecraft_py/Malmo/Minecraft
下的 launchClient.sh,如果能成功运行的话基本没什么问题。若是遇到一些权限的问题,也可以在/usr/local/lib/python3.6/dist-packages/minecraft_py-0.0.2-py3.6.egg/minecraft_py/__init__.py
文件中更改两个路径为第一步时解压后的文件夹路径。
malmo_xsd_path = '/media/lab/data/yongsen/pygame/Malmo/Schemas'
malmo_dir = '/media/lab/data/yongsen/pygame/Malmo'
- 如果有库依赖的报错,只需要安装对应依赖即可。
比如 ImportError: cannot import name '_psutil_linux',sudo /usr/local/bin/pip3.6 install psutil
获取更多精彩,请关注「seniusen」!