Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug Report] AttributeError: module 'gym.envs.atari' has no attribute 'AtariEnv' #2648

Closed
htang6 opened this issue Feb 28, 2022 · 23 comments
Closed

Comments

@htang6
Copy link

htang6 commented Feb 28, 2022

After installing gym and gym[atari], the breakout doesn't work
`
import gym
env = gym.make("ALE/Breakout-v5")
observation = env.reset()
for _ in range(1000):
env.render()
action = env.action_space.sample() # your agent here (this takes random actions)
observation, reward, done, info = env.step(action)

if done:
observation = env.reset()
env.close()

Traceback (most recent call last):
File "/Users/haocheng/playground/PolicyGradient/main.py", line 2, in
env = gym.make("ALE/Breakout-v5")
File "/Users/haocheng/opt/anaconda3/envs/ML/lib/python3.7/site-packages/gym/envs/registration.py", line 676, in make
return registry.make(id, **kwargs)
File "/Users/haocheng/opt/anaconda3/envs/ML/lib/python3.7/site-packages/gym/envs/registration.py", line 520, in make
return spec.make(**kwargs)
File "/Users/haocheng/opt/anaconda3/envs/ML/lib/python3.7/site-packages/gym/envs/registration.py", line 139, in make
cls = load(self.entry_point)
File "/Users/haocheng/opt/anaconda3/envs/ML/lib/python3.7/site-packages/gym/envs/registration.py", line 56, in load
fn = getattr(mod, attr_name)
AttributeError: module 'gym.envs.atari' has no attribute 'AtariEnv'

@pseudo-rnd-thoughts
Copy link
Contributor

Try installing ale-py as v5 uses a different backend module (ale-py) compared to v0 and v4 with atari-lib

pip install ale-py

@pseudo-rnd-thoughts
Copy link
Contributor

@JesseFarebro Could you explain how atari is added to gym.envs.atari as isn't in the git repo
https://github.com/openai/gym/tree/master/gym/envs

Strangely, I have just installed gym to a new repository and am running into the same issue however last week as I was able to submit issue #2624 which had a different issue
pip install gym[all]

import gym
gym.make('ALE/Breakout-v5')

>>> ModuleNotFoundError: No module named 'gym.envs.atari'

@JesseFarebro
Copy link
Contributor

JesseFarebro commented Mar 1, 2022

We are using a somewhat obscure packaging feature in Python called namespace packages. The gym.envs.atari module is in the ALE repository: https://github.com/mgbellemare/Arcade-Learning-Environment/blob/master/src/gym/envs/atari/environment.py

On install PyPi will place gym.envs.atari in the Gym module. When you uninstall ale-py it will remove that module from Gym. One of the issues people face with namespace packages is that they will install Gym in editable mode, i.e., pip install -e. Namespace packages just don't work when you install the root package in editable mode. The Python devs have been discussing standardizing editable packages which will hopefully fix these issues with namespace packages. You can read more here: https://discuss.python.org/t/standardising-editable-mode-installs-runtime-layout-not-hooks/4098

If you are experiencing any issues outside of editable mode feel free to post more info about your environment, e.g., Python version, distribution (pyenv, conda, etc.), OS, etc. You should also always try a fresh pip uninstall gym ale-py && pip install gym[atari]. If this still doesn't work can you post the result of:

ls -l $(python -c 'import site; print(site.getsitepackages()[0])')/gym/envs/{atari,}

@pseudo-rnd-thoughts
Copy link
Contributor

pseudo-rnd-thoughts commented Mar 1, 2022

Thanks, that explains the issue, I was using gym in editable mode

@jkterry1 jkterry1 closed this as completed Mar 2, 2022
@sparisi
Copy link

sparisi commented Mar 28, 2022

I was having the same issue, and reinstalling ale-py worked.

pip install gym[atari]
pip uninstall ale-py
pip install ale-py

Hope this helps others.

@ZhihaoXu
Copy link

I have the same issue and also tried pip uninstall gym ale-py && pip install gym[atari] but does not work. I am running the code on Colab, the output of ls -l $(python -c 'import site; print(site.getsitepackages()[0])')/gym/envs/{atari,} is

/usr/local/lib/python3.7/dist-packages/gym/envs/:
total 80
drwxr-sr-x 3 root staff  4096 Apr 17 06:31 atari
drwxr-sr-x 3 root staff  4096 Apr 17 06:26 box2d
drwxr-sr-x 4 root staff  4096 Apr 17 06:26 classic_control
-rw-r--r-- 1 root staff  5130 Apr 17 06:26 __init__.py
drwxr-sr-x 4 root staff  4096 Apr 17 06:26 mujoco
drwxr-sr-x 2 root staff  4096 Apr 17 06:26 __pycache__
-rw-r--r-- 1 root staff 27364 Apr 17 06:26 registration.py
-rw-r--r-- 1 root staff 20429 Apr 17 06:26 __relocated__.py
drwxr-sr-x 5 root staff  4096 Apr 17 06:26 toy_text

/usr/local/lib/python3.7/dist-packages/gym/envs/atari:
total 24
-rw-r--r-- 1 root staff 14850 Apr 17 06:31 environment.py
-rw-r--r-- 1 root staff    48 Apr 17 06:31 __init__.py
drwxr-sr-x 2 root staff  4096 Apr 17 06:31 __pycache__

@JesseFarebro
Copy link
Contributor

@ZhihaoXu what does your local directory look like? Do you have agym module in your current working directory?

@ZhihaoXu
Copy link

@JesseFarebro Thanks for your reply. I think my problem is related to the setup of the baselines package. After reinstalling the baselines, the problem is solved.

@lebrice
Copy link

lebrice commented Apr 25, 2022

Still somehow doesn't work on my end.

@JesseFarebro
Copy link
Contributor

@lebrice can you give me more information, e.g., what's the output of:

ls -l $(python -c 'import site; print(site.getsitepackages()[0])')/gym/envs/{atari,}
  • What's the directory tree look like in your current working directory? Feel free to post it if you can.
  • How did you install Gym? make sure it's not in editable mode.
  • Make sure there's no file / folder called Gym in your project.
  • Make sure Gym isn't a git submodule.
  • Make sure you're not working out of the Gym project directory, i.e., don't git clone https://github.com/openao/gym && cd gym and work out of that directory.

@lebrice
Copy link

lebrice commented Apr 27, 2022

Nevermind @JesseFarebro , At first I believed there was an older version of gym and/or ale-py in my pip cache.
However it turns out I was inside the gym repository folder (not installed in editable mode).

Here is my "test" of sorts to check if the installation process works.

$ conda create -n temp-atari python=3.9
...
$ conda activate temp-atari
$ pip install gym[atari,accept-rom-license]
...
$ python -c "import gym; print(gym.make('Breakout-v0').reset().shape)"
/<some warning>
A.L.E: Arcade Learning Environment (version 0.7.5+db37282)
[Powered by Stella]
(210, 160, 3)

All is good! Still, I wish it was possible to use the atari envs inside the gym repo! 🤔

@2291924061
Copy link

runfile('C:/Users/liao/Desktop/CNNPong/untitled2.py', wdir='C:/Users/liao/Desktop/CNNPong')
Traceback (most recent call last):

File "D:\Anaconda3\envs\tfgpu\lib\site-packages\spyder_kernels\py3compat.py", line 356, in compat_exec
exec(code, globals, locals)

File "c:\users\liao\desktop\cnnpong\untitled2.py", line 9, in
env = gym.make('PongDeterministic-v4')#PongDeterministic-v4 Pong-v4

File "D:\Anaconda3\envs\tfgpu\lib\site-packages\gym\envs\registration.py", line 676, in make
return registry.make(id, **kwargs)

File "D:\Anaconda3\envs\tfgpu\lib\site-packages\gym\envs\registration.py", line 520, in make
return spec.make(**kwargs)

File "D:\Anaconda3\envs\tfgpu\lib\site-packages\gym\envs\registration.py", line 139, in make
cls = load(self.entry_point)

File "D:\Anaconda3\envs\tfgpu\lib\site-packages\gym\envs\registration.py", line 56, in load
fn = getattr(mod, attr_name)

AttributeError: module 'gym.envs.atari' has no attribute 'AtariEnv' @JesseFarebro

@2291924061
Copy link

Nevermind @JesseFarebro , At first I believed there was an older version of gym and/or ale-py in my pip cache. However it turns out I was inside the gym repository folder (not installed in editable mode).

Here is my "test" of sorts to check if the installation process works.

$ conda create -n temp-atari python=3.9
...
$ conda activate temp-atari
$ pip install gym[atari,accept-rom-license]
...
$ python -c "import gym; print(gym.make('Breakout-v0').reset().shape)"
/<some warning>
A.L.E: Arcade Learning Environment (version 0.7.5+db37282)
[Powered by Stella]
(210, 160, 3)

All is good! Still, I wish it was possible to use the atari envs inside the gym repo! 🤔

hi! bro ,Has your problem been solved I seem to have the same problem as you

@pseudo-rnd-thoughts
Copy link
Contributor

@2291924061 Could you run pip uninstall gym and pip install gym[atari]
Then rerun the results, do you get the same error?

@2291924061
Copy link

I tried to reinstall gym in the way you said, but it didn't help.This problem occurred when I installed the gym environment of 0.23.1.

@2291924061 Could you run pip uninstall gym and pip install gym[atari] Then rerun the results, do you get the same error?

@2291924061
Copy link

@pseudo-rnd-thoughts I have used this environment to run gym 0.19, and it won't have this problem. But when I update gym, he will report this error

@2291924061
Copy link

@pseudo-rnd-thoughts I re created and activated an environment. After configuring the new version of gym, everything will be normal. But the previous environment still doesn't work properly

@pseudo-rnd-thoughts
Copy link
Contributor

ls -l $(python -c 'import site; print(site.getsitepackages()[0])')/gym/envs/{atari,}
What's the directory tree look like in your current working directory? Feel free to post it if you can.
How did you install Gym? make sure it's not in editable mode.
Make sure there's no file / folder called Gym in your project.
Make sure Gym isn't a git submodule.
Make sure you're not working out of the Gym project directory, i.e., don't git clone https://github.com/openao/gym && cd gym and work out of that directory.

What are your results from following @JesseFarebro suggestions?

@2291924061
Copy link

ls -l $(python -c 'import site; print(site.getsitepackages()[0])')/gym/envs/{atari,}
What's the directory tree look like in your current working directory? Feel free to post it if you can.
How did you install Gym? make sure it's not in editable mode.
Make sure there's no file / folder called Gym in your project.
Make sure Gym isn't a git submodule.
Make sure you're not working out of the Gym project directory, i.e., don't git clone https://github.com/openao/gym && cd gym and work out of that directory.

What are your results from following @JesseFarebro suggestions?

In shell mode, this sentence will not report this error.

@pseudo-rnd-thoughts
Copy link
Contributor

Could you also answer the other questions as well
Could you also tell us your operating system, gym version, ale-py version, python version

@haneensalameh66
Copy link

haneensalameh66 commented May 20, 2022

Could you also answer the other questions as well Could you also tell us your operating system, gym version, ale-py version, python version

**_hello, i have almost the same problem with ALE namespace while trying to train a model on Colab by using these lines:

train_env = suite_gym.load('ALE/SpaceInvaders-v5')
evaluation_env = suite_gym.load('ALE/SpaceInvaders-v5')

and it show me this error message:

DeprecatedEnv: Env ALE/SpaceInvaders-v5 not found (valid versions include ['SpaceInvaders-v0', 'SpaceInvaders-v4'])
In call to configurable 'load' (<function load at 0x7f3040f16ef0>)

I have Gym Version: 0.17.3
ale_py Version: 0.7
Python Version : Python 3.7.13_**

@haneensalameh66
Copy link

haneensalameh66 commented May 20, 2022

also i have installed AutoROM-0.4.2

Could you also answer the other questions as well Could you also tell us your operating system, gym version, ale-py version, python version
hello, i have almost the same problem with ALE namespace while trying to train a model on Colab by using these lines:

train_env = suite_gym.load('ALE/SpaceInvaders-v5') evaluation_env = suite_gym.load('ALE/SpaceInvaders-v5')

and it show me this error message:

DeprecatedEnv: Env ALE/SpaceInvaders-v5 not found (valid versions include ['SpaceInvaders-v0', 'SpaceInvaders-v4']) In call to configurable 'load' (<function load at 0x7f3040f16ef0>)

I have Gym Version: 0.17.3 ale_py Version: 0.7 Python Version : Python 3.7.13

@satyrmipt
Copy link

satyrmipt commented Mar 24, 2024

May I post in the closed issue or have to open a new one?
I have had this problem and originally solved it by this tip:

pip install gym[atari]
pip uninstall ale-py
pip install ale-py

but after it i was solving another bug: tensorflow/agents#911
and install previous version of ale-py:

pip install ale-py==0.7.5.

after that the bug AttributeError: 'AtariEnv' object has no attribute 'render_mode' returned and i can not solve it since.

Additional info:

Python version:

(reinf_learning_hw2) C:\Users\satyr>python --version
Python 3.10.14

some magic command:

ls -l $(python -c 'import site; print(site.getsitepackages()[0])')/gym/envs/{atari,}
Invalid switch - "gym

Full package list for conda virtual env:

(reinf_learning_hw2) C:\Users\satyr>conda list
packages in environment at C:\Users\satyr\anaconda3\envs\reinf_learning_hw2:
Name Version Build Channel
absl-py 1.4.0 pypi_0 pypi
ale-py 0.7.5 pypi_0 pypi
appdirs 1.4.4 pypi_0 pypi
asttokens 2.0.5 pyhd3eb1b0_0
autorom 0.4.2 pypi_0 pypi
autorom-accept-rom-license 0.6.1 pypi_0 pypi
blas 1.0 mkl
bzip2 1.0.8 h2bbff1b_5
ca-certificates 2024.3.11 haa95532_0
cachetools 5.3.0 pypi_0 pypi
certifi 2023.5.7 pypi_0 pypi
charset-normalizer 3.1.0 pypi_0 pypi
click 8.1.3 pypi_0 pypi
cloudpickle 2.2.1 py310haa95532_0
colorama 0.4.4 pypi_0 pypi
comm 0.2.1 py310haa95532_0
commonmark 0.9.1 pypi_0 pypi
cycler 0.11.0 pypi_0 pypi
debugpy 1.6.7 py310hd77b12b_0
decorator 4.4.2 pypi_0 pypi
docker-pycreds 0.4.0 pypi_0 pypi
docstring-parser 0.15 pypi_0 pypi
entrypoints 0.4 py310haa95532_0
exceptiongroup 1.2.0 py310haa95532_0
executing 0.8.3 pyhd3eb1b0_0
farama-notifications 0.0.4 py310haa95532_0
filelock 3.12.0 pypi_0 pypi
fonttools 4.38.0 pypi_0 pypi
gitdb 4.0.10 pypi_0 pypi
gitpython 3.1.31 pypi_0 pypi
google-auth 2.18.0 pypi_0 pypi
google-auth-oauthlib 0.4.6 pypi_0 pypi
grpcio 1.54.0 pypi_0 pypi
gym 0.23.1 pypi_0 pypi
gym-notices 0.0.8 pypi_0 pypi
gymnasium 0.28.1 py310haa95532_0

huggingface-hub 0.11.1 pypi_0 pypi
idna 3.4 pypi_0 pypi
imageio 2.28.1 pypi_0 pypi
imageio-ffmpeg 0.3.0 pypi_0 pypi
importlib-resources 6.4.0 pypi_0 pypi
intel-openmp 2023.1.0 h59b6b97_46320
ipykernel 6.28.0 py310haa95532_0
ipython 8.20.0 py310haa95532_0
jax-jumpy 1.0.0 py310haa95532_0
jedi 0.18.1 py310haa95532_1
jupyter_client 7.4.9 py310haa95532_0
jupyter_core 5.5.0 py310haa95532_0
kiwisolver 1.4.4 pypi_0 pypi
libffi 3.4.4 hd77b12b_0
libsodium 1.0.18 h62dcd97_0
markdown 3.3.7 pypi_0 pypi
markupsafe 2.1.2 pypi_0 pypi
matplotlib 3.5.3 pypi_0 pypi
matplotlib-inline 0.1.6 py310haa95532_0
mkl 2023.1.0 h6b88ed4_46358
mkl-service 2.4.0 py310h2bbff1b_1
mkl_fft 1.3.8 py310h2bbff1b_0
mkl_random 1.2.4 py310h59b6b97_0
moviepy 1.0.3 pypi_0 pypi
nest-asyncio 1.6.0 py310haa95532_0
numpy 1.24.4 pypi_0 pypi
numpy-base 1.26.4 py310h65a83cf_0
oauthlib 3.2.2 pypi_0 pypi
openssl 3.0.13 h2bbff1b_0
packaging 23.1 pypi_0 pypi
pandas 1.3.5 pypi_0 pypi
parso 0.8.3 pyhd3eb1b0_0
pathtools 0.1.2 pypi_0 pypi
pillow 9.5.0 pypi_0 pypi
pip 23.3.1 py310haa95532_0
platformdirs 3.10.0 py310haa95532_0
proglog 0.1.10 pypi_0 pypi
prompt-toolkit 3.0.43 py310haa95532_0
prompt_toolkit 3.0.43 hd3eb1b0_0
protobuf 3.20.3 pypi_0 pypi
psutil 5.9.5 pypi_0 pypi
pure_eval 0.2.2 pyhd3eb1b0_0
pyasn1 0.5.0 pypi_0 pypi
pyasn1-modules 0.3.0 pypi_0 pypi
pygame 2.1.0 pypi_0 pypi
pygments 2.15.1 py310haa95532_1
pyparsing 3.0.9 pypi_0 pypi
python 3.10.14 he1021f5_0
python-dateutil 2.8.2 pyhd3eb1b0_0
python_abi 3.10 2_cp310 conda-forge
pytz 2023.3 pypi_0 pypi
pywin32 305 py310h2bbff1b_0
pyyaml 6.0.1 pypi_0 pypi
pyzmq 25.1.2 py310hd77b12b_0
requests 2.30.0 pypi_0 pypi
requests-oauthlib 1.3.1 pypi_0 pypi
rich 11.2.0 pypi_0 pypi
rsa 4.7.2 pypi_0 pypi
sentry-sdk 1.22.2 pypi_0 pypi
setproctitle 1.3.2 pypi_0 pypi
setuptools 67.7.2 pypi_0 pypi
shtab 1.6.4 pypi_0 pypi
six 1.16.0 pyhd3eb1b0_1
smmap 5.0.0 pypi_0 pypi
spyder-kernels 2.4.1 py310haa95532_0
sqlite 3.41.2 h2bbff1b_0
stable-baselines3 2.0.0 pypi_0 pypi
stack_data 0.2.0 pyhd3eb1b0_0
tbb 2021.8.0 h59b6b97_0
tenacity 8.2.3 pypi_0 pypi
tensorboard 2.11.2 pypi_0 pypi
tensorboard-data-server 0.6.1 pypi_0 pypi
tensorboard-plugin-wit 1.8.1 pypi_0 pypi
tk 8.6.12 h2bbff1b_0
torch 1.12.1 pypi_0 pypi
tornado 6.3.3 py310h2bbff1b_0
tqdm 4.65.0 pypi_0 pypi
traitlets 5.7.1 py310haa95532_0
typing-extensions 4.5.0 pypi_0 pypi
typing_extensions 4.9.0 py310haa95532_1
tyro 0.5.10 pypi_0 pypi
tzdata 2024a h04d1e81_0
urllib3 1.26.15 pypi_0 pypi
vc 14.2 h21ff451_1
vs2015_runtime 14.27.29016 h5e58377_2
wandb 0.13.11 pypi_0 pypi
wcwidth 0.2.5 pyhd3eb1b0_0
werkzeug 2.2.3 pypi_0 pypi
wheel 0.40.0 pypi_0 pypi
xz 5.4.6 h8cc25b3_0
zeromq 4.3.5 hd77b12b_0
zlib 1.2.13 h8cc25b3_0

also see screenshot in attachment
error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants