搞了一大堆还是搞不出来放弃了
最后用matplotlib画出来看
bash
import gym
import matplotlib.pyplot as plt
from IPython import display
import numpy as np
%matplotlib inline
env = gym.make('CartPole-v1', render_mode="rgb_array")
observation = env.reset()
a = 0
for _ in range(100):
img = env.render()
if img is not None:
if _ % 10 ==0: # 加速动画
if isinstance(img, list):
img = img[0]
img = np.array(img)
img = img.squeeze()
plt.imshow(img)
display.display(plt.gcf())
display.clear_output(wait=True)
action = env.action_space.sample()
step_result = env.step(action)
env.close()
适配环境命令失败记录
下载的依赖
bash
apt-get install libgl1-mesa-dri libgl1-mesa-glx libegl1-mesa libgles2-mesa libxrandr2 libxinerama1 libxcursor1 libegl-mesa0
apt-get install xserver-xorg-video-nouveau
apt-get install mesa-utils mesa-utils-extra
apt-get install xserver-xorg
apt-get install locales
dpkg-reconfigure locales
# 选择 en_US.UTF-8 UTF-8
dpkg-reconfigure mesa-utils
apt-get install xvfb xorg xauth
apt-get install python3-opengl
更改的文件
bash
mkdir -p /usr/lib/dri
ln -s /usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so /usr/lib/dri/nouveau_dri.so
mv /root/anaconda3/envs/agent/lib/libstdc++.so.6 /root/anaconda3/envs/agent/lib/libstdc++.so.6.backup
ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /root/anaconda3/envs/agent/lib/
设置的环境变量
bash
export LIBGL_ALWAYS_SOFTWARE=1
export LIBGL_ALWAYS_SOFTWARE=true
Xvfb :99 &
export DISPLAY=:0