I don't know the particular reason why this happens, but for latest chipsets (m1,m2,m1 pro,m1 max) are not rendering the environment of the gym while the algorithm works just as fine as normal. Fortunately I have found one fix for this problem. For that, we need to use miniconda.
install miniconda in your MacBook. For that, open terminal, type
$ wget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh
$ sh ./Miniconda3-latest-MacOSX-x86_64.sh
press enter and yes for all the terms and conditions (if you are okay with them)
then, activate the conda environment by
conda miniconda3/bin/activate
once it is active, you will get (base)
prefix indicating its active.
Once it is done, continue with gym installation by,
Note: this did not work for me when I created a virtual env in the conda. I use just the base version to render and it works.
conda install -c conda-forge gym
this will install all requirements and libraries.
You can test the rendering by executing the following code:
import gym
env = gym.make('MountainCarContinuous-v0')
for i_episode in range(20):
observation = env.reset()
for t in range(100):
env.render()
print(observation)
action = env.action_space.sample()
obs, reward, done, info = env.step(action)
print(obs, reward, done)
if done:
print("Episode finished after {} timesteps".format(t+1))
break
env.close()
Hope this helps.