-
google colab 환경에서 No available video device 에러 해결python source code 2023. 5. 27. 08:41728x90
구글 코랩에서 강화학습 등의 시뮬레이션이 필요한 코드를 실행 시 아래와 같은
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 를 위한 별도 코드를 생성해야 한다.
이 부분에 대해서는 다음 글에서 다뤄보도록....
반응형'python source code' 카테고리의 다른 글
Streamlit 모듈을 활용한 웹 페이지 디자인 (사이트) (0) 2023.06.09 openAI gym API 관련 예제 (1) 2023.05.29 파이썬을 활용한 강화학습 (0) 2023.05.24 파이썬 언어의 특징, 산업계에 응용될 수 있는 파이썬 skills (0) 2023.05.23 Mnist를 이용한 GAN example (0) 2023.03.20