ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • google colab 환경에서 No available video device 에러 해결
    python source code 2023. 5. 27. 08:41
    728x90

     

     

    구글 코랩에서 강화학습 등의 시뮬레이션이 필요한 코드를 실행 시 아래와 같은 

    No available video device

    에러가 발생한다.

     

    /usr/local/lib/python3.10/dist-packages/gym/envs/registration.py:593: UserWarning: WARN: The environment CartPole-v0 is out of date. You should consider upgrading to version `v1`.
      logger.warn(
    /usr/local/lib/python3.10/dist-packages/gym/core.py:317: DeprecationWarning: WARN: Initializing wrapper in old step API which returns one bool instead of two. It is recommended to set `new_step_api=True` to use new step API. This will be the default behaviour in future.
      deprecation(
    /usr/local/lib/python3.10/dist-packages/gym/wrappers/step_api_compatibility.py:39: DeprecationWarning: WARN: Initializing environment in old step API which returns one bool instead of two. It is recommended to set `new_step_api=True` to use new step API. This will be the default behaviour in future.
      deprecation(
    /usr/local/lib/python3.10/dist-packages/gym/core.py:49: DeprecationWarning: WARN: You are calling render method, but you didn't specified the argument render_mode at environment initialization. To maintain backward compatibility, the environment will render in human mode.
    If you want to render in human mode, initialize the environment in this way: gym.make('EnvName', render_mode='human') and don't call the render method.
    See here for more information: https://www.gymlibrary.ml/content/api/
      deprecation(
    ---------------------------------------------------------------------------
    error                                     Traceback (most recent call last)
    <ipython-input-1-13693d494ab9> in <cell line: 4>()
          6     observation = env.reset()
          7     for t in range(100):
    ----> 8         env.render()
          9         # 행동(action)을 취하기 이전에 환경에 대해 얻은 관찰값(observation)
         10         print('observation before action:')
    
    11 frames
    /usr/local/lib/python3.10/dist-packages/gym/envs/classic_control/cartpole.py in _render(self, mode)
        230             pygame.init()
        231             if mode == "human":
    --> 232                 pygame.display.init()
        233                 self.screen = pygame.display.set_mode(
        234                     (self.screen_width, self.screen_height)
    
    error: No available video device

     

    이때,  환경변수와 gygame 모듈을 사용하여 게임 환경 상에서 구동이 가능하게 설정을 하면 해결이 가능하다.

     

    import os
    os.environ['SDL_VIDEODRIVER']='dummy'
    import pygame
    pygame.display.set_mode((640,480))

    아래와 같이 문제는 해결되었지만 display 를 위한 별도 코드를 생성해야 한다.

     

    이 부분에 대해서는 다음 글에서 다뤄보도록....

     

     

    반응형
Designed by Tistory.