Farama-Foundation / Arcade-Learning-Environment

The Arcade Learning Environment (ALE) -- a platform for AI research.
https://ale.farama.org/
GNU General Public License v2.0
2.17k stars 423 forks source link

RuntimeError: Failed to initialize SDL #451

Closed dyllanwli closed 2 years ago

dyllanwli commented 2 years ago

[Environments]:

[Reproduce]:

import ale_py
import gym
env = gym.make('ALE/FishingDerby-v5', render_mode='human')

Then I got runtime error:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-5-26044f6f8f13> in <module>
----> 1 env = gym.make('ALE/FishingDerby-v5', render_mode='human')

~/miniconda3/lib/python3.8/site-packages/gym/envs/registration.py in make(id, **kwargs)
    674 # fmt: on
    675 def make(id: str, **kwargs) -> "Env":
--> 676     return registry.make(id, **kwargs)
    677 
    678 

~/miniconda3/lib/python3.8/site-packages/gym/envs/registration.py in make(self, path, **kwargs)
    518         spec = self.spec(path)
    519         # Construct the environment
--> 520         return spec.make(**kwargs)
    521 
    522     def all(self):

~/miniconda3/lib/python3.8/site-packages/gym/envs/registration.py in make(self, **kwargs)
    138         else:
    139             cls = load(self.entry_point)
--> 140             env = cls(**_kwargs)
    141 
    142         # Make the environment aware of which spec it came from.

~/miniconda3/lib/python3.8/site-packages/gym/envs/atari/environment.py in __init__(self, game, mode, difficulty, obs_type, frameskip, repeat_action_probability, full_action_space, render_mode)
    121 
    122         # Seed + Load
--> 123         self.seed()
    124 
    125         self._action_set = (

~/miniconda3/lib/python3.8/site-packages/gym/envs/atari/environment.py in seed(self, seed)
    178                 "https://github.com/mgbellemare/Arcade-Learning-Environment#rom-management"
    179             )
--> 180         self.ale.loadROM(getattr(roms, self._game))
    181 
    182         if self._game_mode is not None:

RuntimeError: Failed to initialize SDL

I was trying to add human render mode to my research to use env.render()

blackwint3r commented 2 years ago

Have the same problem under Mac m1! Here is my test code:

from ale_py import ALEInterface, SDL_SUPPORT
ale = ALEInterface()
ale.setInt("random_seed", 123)
if SDL_SUPPORT:
    ale.setBool("sound", True)
    ale.setBool("display_screen", True)
from ale_py.roms import Breakout
ale.loadROM(Breakout)  # <--   RuntimeError: Failed to initialize SDL
JesseFarebro commented 2 years ago

@dyllanwli what platform are you running on? Arm as well?

Senhongl commented 2 years ago

Same issue on my Mac M1 chip as well and everything works well on my Mac with intel chip.

JesseFarebro commented 2 years ago

Hmm, okay, would someone be willing to test some custom wheels I'll upload to https://test.pypi.org/? I don't have access to an M1 machine and I have no way of testing this. I blindly decided to build the ARM wheels for macOS but I guess there are some issues after all 😞 .

turboka11e commented 2 years ago

I had the same issue with M1 but solved the issue by replacing the "libSDL2-2.0.dylib" in the site package from ale-py with another one. I replaced it with the "libSDL2-2.0.0.dylib" (Notice: slightly different name needs to be changed) from the site-package pygame. However the problem did not occur on all ARM machines, for example on Jetson AGX Developer Kit, which runs ARM Ubuntu 18.04.

turboka11e commented 2 years ago

Hmm, okay, would someone be willing to test some custom wheels I'll upload to https://test.pypi.org/? I don't have access to an M1 machine and I have no way of testing this. I blindly decided to build the ARM wheels for macOS but I guess there are some issues after all 😞 .

I could test it. I have an M1 Pro (MacBook Pro 16")

JesseFarebro commented 2 years ago

@turboka11e that's very unusual. So you're saying that renaming the file libSDL2-2.0.dylib to libSDL2-2.0.0.dylib inside of the ALE's site-packages folder fixed this issue? When we build the Python wheels we specifically give the filename of the dynamic library before we copy it (https://github.com/mgbellemare/Arcade-Learning-Environment/blob/master/src/python/CMakeLists.txt#L65). I can't imagine why there would be this mismatch.

I'll put together a test wheel that has extra debugging info so we can get to the bottom of this. I'll update this post once I've published it to PyPi test.

turboka11e commented 2 years ago

@JesseFarebro Sorry, that's not what I've meant. I was replacing the original libSDL2-2.0.dylib from another package pygame, as a hotfix to get it working. But they would name it slightly different, hence that's why I needed to change the name. So the problem is not a matching error, but must be something else. Alright perfect, I'll wait for the update. 👍🏼

JesseFarebro commented 2 years ago

@turboka11e can you try this build: https://test.pypi.org/project/ale-py/0.7.5/.

pip install -i https://test.pypi.org/simple/ ale-py==0.7.5
turboka11e commented 2 years ago

@JesseFarebro I created a new python test venv and tried the build, but unfortunately it has a error.

(test-venv) lukaskaluscha@Lukass-MBP-2 test % pip --version
pip 22.0.4 from /Users/lukaskaluscha/Desktop/test/test-venv/lib/python3.9/site-packages/pip (python 3.9)
(test-venv) lukaskaluscha@Lukass-MBP-2 test % pip install -i https://test.pypi.org/simple/ ale-py==0.7.5
Looking in indexes: https://test.pypi.org/simple/
Collecting ale-py==0.7.5
  Downloading https://test-files.pythonhosted.org/packages/53/7e/858fc1bc12d293648539d308b3a4fedea07b54fd410c9475db5fc46eec2a/ale_py-0.7.5%2Bf3e60d1-cp39-cp39-macosx_11_0_arm64.whl (1.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.0/1.0 MB 2.0 MB/s eta 0:00:00
Discarding https://test-files.pythonhosted.org/packages/53/7e/858fc1bc12d293648539d308b3a4fedea07b54fd410c9475db5fc46eec2a/ale_py-0.7.5%2Bf3e60d1-cp39-cp39-macosx_11_0_arm64.whl#sha256=745ee6c7c79cf6ef94b774bae2359f492ba086b9776f63fcbaec5e2d26957fbd (from https://test.pypi.org/simple/ale-py/) (requires-python:>=3.7): Requested ale-py==0.7.5 from https://test-files.pythonhosted.org/packages/53/7e/858fc1bc12d293648539d308b3a4fedea07b54fd410c9475db5fc46eec2a/ale_py-0.7.5%2Bf3e60d1-cp39-cp39-macosx_11_0_arm64.whl#sha256=745ee6c7c79cf6ef94b774bae2359f492ba086b9776f63fcbaec5e2d26957fbd has inconsistent version: filename has '0.7.5+f3e60d1', but metadata has '0.7.5'
  Downloading https://test-files.pythonhosted.org/packages/1f/1b/4694238733bc7609fceffe68d1df190d1a5464e888799c93ebe280b34c7b/ale_py-0.7.5%2Bdb37282-cp39-cp39-macosx_11_0_arm64.whl (1.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.0/1.0 MB 2.1 MB/s eta 0:00:00
Discarding https://test-files.pythonhosted.org/packages/1f/1b/4694238733bc7609fceffe68d1df190d1a5464e888799c93ebe280b34c7b/ale_py-0.7.5%2Bdb37282-cp39-cp39-macosx_11_0_arm64.whl#sha256=da5be311285a00e587b886805ea56762d44bf4f1da672229c1fbaff209bfcdc2 (from https://test.pypi.org/simple/ale-py/) (requires-python:>=3.7): Requested ale-py==0.7.5 from https://test-files.pythonhosted.org/packages/1f/1b/4694238733bc7609fceffe68d1df190d1a5464e888799c93ebe280b34c7b/ale_py-0.7.5%2Bdb37282-cp39-cp39-macosx_11_0_arm64.whl#sha256=da5be311285a00e587b886805ea56762d44bf4f1da672229c1fbaff209bfcdc2 has inconsistent version: filename has '0.7.5+db37282', but metadata has '0.7.5'
  Downloading https://test-files.pythonhosted.org/packages/e0/43/d46a3a01188af749695dce015b90e8e8d5c9f8bba1a9eea891d33de5d363/ale_py-0.7.5%2Bbfdd2b6-cp39-cp39-macosx_11_0_arm64.whl (1.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.0/1.0 MB 1.8 MB/s eta 0:00:00
Discarding https://test-files.pythonhosted.org/packages/e0/43/d46a3a01188af749695dce015b90e8e8d5c9f8bba1a9eea891d33de5d363/ale_py-0.7.5%2Bbfdd2b6-cp39-cp39-macosx_11_0_arm64.whl#sha256=6090f588f39e76f2a1b127469c3c0c86b5020117568b0ad3ea30b361eb39f37b (from https://test.pypi.org/simple/ale-py/) (requires-python:>=3.7): Requested ale-py==0.7.5 from https://test-files.pythonhosted.org/packages/e0/43/d46a3a01188af749695dce015b90e8e8d5c9f8bba1a9eea891d33de5d363/ale_py-0.7.5%2Bbfdd2b6-cp39-cp39-macosx_11_0_arm64.whl#sha256=6090f588f39e76f2a1b127469c3c0c86b5020117568b0ad3ea30b361eb39f37b has inconsistent version: filename has '0.7.5+bfdd2b6', but metadata has '0.7.5'
  Downloading https://test-files.pythonhosted.org/packages/35/98/31c82bbfa32ff53c084b044b5693f3fdff524e47220b5641487aebaff4cd/ale_py-0.7.5%2B7e27732-cp39-cp39-macosx_11_0_arm64.whl (1.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.0/1.0 MB 1.8 MB/s eta 0:00:00
Discarding https://test-files.pythonhosted.org/packages/35/98/31c82bbfa32ff53c084b044b5693f3fdff524e47220b5641487aebaff4cd/ale_py-0.7.5%2B7e27732-cp39-cp39-macosx_11_0_arm64.whl#sha256=4dcc67787a107bd4d5b0bea9e6ac64309c87ff8d06967fc9aacb8f7a6b5557b0 (from https://test.pypi.org/simple/ale-py/) (requires-python:>=3.7): Requested ale-py==0.7.5 from https://test-files.pythonhosted.org/packages/35/98/31c82bbfa32ff53c084b044b5693f3fdff524e47220b5641487aebaff4cd/ale_py-0.7.5%2B7e27732-cp39-cp39-macosx_11_0_arm64.whl#sha256=4dcc67787a107bd4d5b0bea9e6ac64309c87ff8d06967fc9aacb8f7a6b5557b0 has inconsistent version: filename has '0.7.5+7e27732', but metadata has '0.7.5'
  Downloading https://test-files.pythonhosted.org/packages/a7/a7/385a92da541b2f536c32403cbce3769f8eedc429dab2acb0a4c5253df958/ale_py-0.7.5%2B30f56cf-cp39-cp39-macosx_11_0_arm64.whl (1.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.0/1.0 MB 1.5 MB/s eta 0:00:00
Discarding https://test-files.pythonhosted.org/packages/a7/a7/385a92da541b2f536c32403cbce3769f8eedc429dab2acb0a4c5253df958/ale_py-0.7.5%2B30f56cf-cp39-cp39-macosx_11_0_arm64.whl#sha256=ed6e8c6810b0a2baae8a41be0e59ea98c33d5cadd46d111be5200006036ce647 (from https://test.pypi.org/simple/ale-py/) (requires-python:>=3.7): Requested ale-py==0.7.5 from https://test-files.pythonhosted.org/packages/a7/a7/385a92da541b2f536c32403cbce3769f8eedc429dab2acb0a4c5253df958/ale_py-0.7.5%2B30f56cf-cp39-cp39-macosx_11_0_arm64.whl#sha256=ed6e8c6810b0a2baae8a41be0e59ea98c33d5cadd46d111be5200006036ce647 has inconsistent version: filename has '0.7.5+30f56cf', but metadata has '0.7.5'
ERROR: Could not find a version that satisfies the requirement ale-py==0.7.5 (from versions: 0.7rc4+5b4e75e, 0.7+6d3b8ab, 0.7+80025fd, 0.7+a54a328, 0.7+d213611, 0.7.1rc0+dd9a841, 0.7.1+b7b0c1a, 0.7.1+dd9a841, 0.7.2+a7a216c, 0.7.3+978d2ce, 0.7.4+069f8bd, 0.7.4+286bdea, 0.7.4+3e89471, 0.7.4+480d996, 0.7.4+732fbdc, 0.7.4+fe6e0d9, 0.7.5+30f56cf, 0.7.5+7e27732, 0.7.5+bfdd2b6, 0.7.5+db37282, 0.7.5+f3e60d1)
ERROR: No matching distribution found for ale-py==0.7.5
JesseFarebro commented 2 years ago

Sorry about that, you can now download 0.7.5 from the main PyPi repository. Let me know if that fixes this problem! Thanks for helping test this out 😄.

turboka11e commented 2 years ago

Hurray - it works!

My script to test it:

import gym

env = gym.make('ALE/Breakout-v5', render_mode='human')

env.reset()
for _ in range(1000):
    env.step(env.action_space.sample())
env.close()

Added ROMS and installed gym 0.23.1.

Thanks a lot :) @JesseFarebro