gym是个强化学习的环境库,初学不想手写个游戏,用它是在方便不过的,但是很难安装。
这里从头介绍,先再anaconda里建个环境然后激活,执行如下安装命令:
python -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install torch -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install torchvision -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install mujoco-py==2.0.2.8 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install atari-py -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install tensorflow-gpu -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install scikit-image -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install visdom -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install tensorboardX -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install gensim -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install py2neo -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install pycocotools -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install wheel -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install gevent -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install libffi-dev -i https://pypi.tuna.tsinghua.edu.cn/simple
至此复制粘贴就可以,下面有些难度了
先安装zlib Index of /fossils
下载到一个位置 执行./configure
make
make install
--------------------------------------------------------------
#安装pcre,PCRE download | SourceForge.net下载
然后解压:unzip pcre-8.45.zip
cd pcre-8.45
./configure --prefix=/usr \
--docdir=/usr/share/doc/pcre-8.45 \
--enable-unicode-properties \
--enable-pcre16 \
--enable-pcre32 \
--enable-pcregrep-libz \
--enable-pcregrep-libbz2 \
--enable-pcretest-libreadline \
--disable-static &&
make
make install
如果没有bzlib.h:则切换到管理员执行
apt-get install zlib1g
apt-get install libbz2-dev
apt-get install apt-get install libboost-all-dev
如果没有readline/readline.h:可忽略,不管它
--------------------------------------------------------------------------
然后安装swig
下载Survey
然后导入linux某个位置,解压,进入目录下(类似之前pcre的步骤),,执行
./configure --prefix=/usr \
--without-clisp \
--without-maximum-compile-warnings &&
make
make install
install -v -m755 -d /usr/share/doc/swig-4.0.2
cp -v -R Doc/* /usr/share/doc/swig-4.0.2
可能报错:缺少libpcre.so.1,则进入linux的usr/lib文件夹,再把pcre-8.41/.libs/libpcre.so.1复制到usr/lib下。之后再进入swig-4.0.2的目录下,重新执行上面命令
-----------------------------------------------------------------------
然后安装mujoco-py和Mujoco,先下载Mujoco
MuJoCo
去这个网站下载mujoco150,mujoco200全下载解压,还有许可证mjket.txt
再linux上随便找个位置新建.mujoco文件,把mujoco150和mujoco200放在这里,然后把mjket.txt分别复制到:.mujoco,.mujoco/mujoco200/bin,.mujoco/mujoco200/bin
然后添加环境(我的路径是:~/.mujoco/mjpro150/bin),先添加150,错了后面有提示:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/.mujoco/mjpro150/bin
然后安装mujoco-py,一定要安装patchelf:
curl -o /usr/local/bin/patchelf https://s3-us-west-2.amazonaws.com/openai-sci-artifacts/manual-builds/patchelf_0.9_amd64.elf
sudo chmod +x /usr/local/bin/patchelf
pip install mujoco-py==2.0.2.8 -i https://pypi.tuna.tsinghua.edu.cn/simple
然后运行
python
import mujoco_py
查看是否安装好,如果提示报错,并且是mujoco版本不对,会提示你添加环境变量
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/.mujoco/mjpro200/bin
,再看看。
然后执行
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/hz3/.mujoco/mjpro150/bin/
pip install box2d -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install box2d-py -i https://pypi.tuna.tsinghua.edu.cn/simple
没有报错则:
pip install gym[all] -i https://pypi.tuna.tsinghua.edu.cn/simple
如果报错不能访问patchelf,则:sudo chmod +x /usr/local/bin/patchelf
如果报错:Note: Gym no longer distributes ROMs.
则pip install gym[accept-rom-license]
如果没有GL/osmesa.h:则切换到管理员:sudo apt-get install libosmesa6-dev
至此安装完毕,
如果不安装mujoco_py直接pip install gym不报错,但不能全部安装完成,用gym库时候不能导入环境。