Linux下配置强化学习环境

在WSL ubuntu 20.04下,配置配置强化学习环境(PyTorch、Anaconda、Jupyter NoteBook)

一、 Linux下配置强化学习环境

我个人使用的WSL ubuntu 20.04,PyTorch、Anaconda、Jupyter NoteBook

1.1 安装Anaconda

到官网下载相应版本Download Now | Anaconda

例如我下载的是Anaconda3-2024.02-1-Linux-x86_64.sh

打开下载路径,运行

1
bash Anaconda3-2024.02-1-Linux-x86_64.sh

出现下列提示:

1
2
3
4
5
6
If you'd prefer that conda's base environment not be activated on startup,
run the following command when conda is activated:

conda config --set auto_activate_base false

You can undo this by running `conda init --reverse $SHELL`? [yes|no]

根据自己需要选择即可

创建环境

1
conda create --name rl python=填python版本号

结果如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
Downloading and Extracting Packages:

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate rl
#
# To deactivate an active environment, use
#
# $ conda deactivate

运行下列命令行,检查自己环境是否创建成功

1
conda env list

结果如下:

1
2
3
4
# conda environments:
#
base * /xxxx/anaconda3
rl /xxxx/anaconda3/envs/rl

查看创建成功的环境

1
conda env list

激活指定的环境

1
activate rl

退出创建的环境

1
conda deactivate

删除所创建的环境rl(--all,完全删除)

1
conda remove --name rl --all

1.2 PyTorch安装

官网:PyTorch

image-20240428182007432

点击进入Get Started界面,按需要选择配置之后,将"Run this Command"的命令复制到命令行里。

1.3 Jupyter Notebook的安装

终端使用命令行

1
pip install jupyter notebook

安装完成之后打开Jupyter Notebook

命令行输入:

1
jupyter notebook

复制终端里的相应链接到浏览器打开

image-20240512133610159

image-20240512133954633image-20240512134056096

1.4 GYM

github源码网址:[GitHub - openai/gym: A toolkit for developing and comparing reinforcement learning algorithms.] (https://github.com/openai/gym)

1
git clone http://github.com/openai/gym.git

注释掉setup.py里的

image-20240512145155947
1
2
cd gym
pip install -e '.[all]'

出现报错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
× python setup.py bdist_wheel did not run successfully.
exit code: 1
╰─> [17 lines of output]
Using setuptools (version 45.2.0).
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.8
creating build/lib.linux-x86_64-3.8/Box2D
copying library/Box2D/Box2D.py -> build/lib.linux-x86_64-3.8/Box2D
copying library/Box2D/__init__.py -> build/lib.linux-x86_64-3.8/Box2D
creating build/lib.linux-x86_64-3.8/Box2D/b2
copying library/Box2D/b2/__init__.py -> build/lib.linux-x86_64-3.8/Box2D/b2
running build_ext
building 'Box2D._Box2D' extension
swigging Box2D/Box2D.i to Box2D/Box2D_wrap.cpp
swig -python -c++ -IBox2D -small -O -includeall -ignoremissing -w201 -globals b2Globals -outdir library/Box2D -keyword -w511 -D_SWIG_KWARGS -o Box2D/Box2D_wrap.cpp Box2D/Box2D.i
unable to execute 'swig': No such file or directory
error: command 'swig' failed with exit status 1
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for box2d-py
Running setup.py clean for box2d-py
Building wheel for moviepy (setup.py) ... done
Created wheel for moviepy: filename=moviepy-1.0.3-py3-none-any.whl size=110730 sha256=dff0c45a7ab8b9f1a6aa63deda2acd8f111892411080fbb8d039ced27cb2fe20
Stored in directory:

原因是没有下载SWIG

1
2
sudo apt update
sudo apt install swig

检查是否安装成功

1
swig -version

Linux下配置强化学习环境
http://example.com/2024/05/17/强化学习配置环境/
Author
John Doe
Posted on
May 17, 2024
Licensed under