Farama-Foundation / Minigrid

Simple and easily configurable grid world environments for reinforcement learning
https://minigrid.farama.org/
Other
2.09k stars 604 forks source link

[Bug Report] Cannot create any env, TypeError: 'NoneType' object is not subscriptable #292

Closed sparisi closed 1 year ago

sparisi commented 1 year ago

Just installed this repo with pip install minigrid. Using python 3.10.9 on Win 11.

import gymnasium
gymnasium.make('MiniGrid-Unlock-v0')

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\xxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\gymnasium\core.py", line 383, in __repr__
    return str(self)
  File "C:\Users\xxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\gymnasium\core.py", line 379, in __str__
    return f"<{type(self).__name__}{self.env}>"
  File "C:\Users\xxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\gymnasium\core.py", line 379, in __str__
    return f"<{type(self).__name__}{self.env}>"
  File "C:\Users\xxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\minigrid\minigrid_env.py", line 207, in __str__
    if i == self.agent_pos[0] and j == self.agent_pos[1]:
TypeError: 'NoneType' object is not subscriptable

This happens with any env I tried except the empty minigrid.

I have checked that there is no similar issue in the repo.

pseudo-rnd-thoughts commented 1 year ago

You don't have it in your example code but I think you are printing the environment. Minigrid implements a different print function than gym where the print actually provides a string-based grid of the current environment. Therefore, you should be able to solve this through just avoiding the print statement until you have reset the environment.

We should be able to raise a more helpful error so thanks for the issue

sparisi commented 1 year ago

Oh right! This is the first time I use the new minigrid + gymnasium, and in the old gym_minigrid the env was just printed as a matrix of strings without problems. Anyway, I can run experiments and that's what matters. Thanks!