AttributeError Traceback (most recent call last)
Cell In[2], line 35
32 action = np.argmax(Q_table[state, :]) # Q-테이블 기반 행동
34 # 행동 실행 & 다음 상태, 보상, 종료 여부 받기
---> 35 new_state, reward, terminated, truncated, _ = env.step(action)
36 done = terminated or truncated
38 # Q-값 업데이트 (Bellman Equation)
File ~\ml\env\Lib\site-packages\gym\wrappers\time_limit.py:50, in TimeLimit.step(self, action)
39 def step(self, action):
40 """Steps through the environment and if the number of steps elapsed exceeds ``max_episode_steps`` then truncate.
41
42 Args:
(...) 48
49 """
---> 50 observation, reward, terminated, truncated, info = self.env.step(action)
51 self._elapsed_steps += 1
53 if self._elapsed_steps >= self._max_episode_steps:
File ~\ml\env\Lib\site-packages\gym\wrappers\order_enforcing.py:37, in OrderEnforcing.step(self, action)
35 if not self._has_reset:
36 raise ResetNeeded("Cannot call env.step() before calling env.reset()")
---> 37 return self.env.step(action)
File ~\ml\env\Lib\site-packages\gym\wrappers\env_checker.py:37, in PassiveEnvChecker.step(self, action)
35 if self.checked_step is False:
36 self.checked_step = True
---> 37 return env_step_passive_checker(self.env, action)
38 else:
39 return self.env.step(action)
File ~\ml\env\Lib\site-packages\gym\utils\passive_env_checker.py:233, in env_step_passive_checker(env, action)
230 obs, reward, terminated, truncated, info = result
232 # np.bool is actual python bool not np boolean type, therefore bool_ or bool8
--> 233 if not isinstance(terminated, (bool, np.bool8)):
234 logger.warn(
235 f"Expects `terminated` signal to be a boolean, actual type: {type(terminated)}"
236 )
237 if not isinstance(truncated, (bool, np.bool8)):
File ~\ml\env\Lib\site-packages\numpy\__init__.py:427, in __getattr__(attr)
424 import numpy.char as char
425 return char.chararray
--> 427 raise AttributeError("module {!r} has no attribute "
428 "{!r}".format(__name__, attr))
AttributeError: module 'numpy' has no attribute 'bool8'
Frozen Lake 환경 실행 시 다음과 같은 에러가 발생AttributeError: module 'numpy' has no attribute 'bool8'
numpy 최신 버전(1.24 이상)에서는 np.bool8 타입이 제거되었습니다.
gym 라이브러리는 내부적으로 np.bool8 타입을 사용하고 있어 호환성 문제가 발생합니다.
gym과 numpy 버전 충돌로 인해 발생하는 문제입니다.
gym과 numpy를 호환되는 버전으로 설치gym: 0.26.2
numpy: 1.23.5
pip install gym==0.26.2
pip install gym[toy_text]==0.26.2
pip install numpy==1.23.5
# 새로운 가상환경 생성
python -m venv rl_env
source rl_env/bin/activate # Windows: rl_env\Scripts\activate
# 패키지 설치
pip install gym==0.26.2
pip install gym[toy_text]==0.26.2
pip install numpy==1.23.5
pip install pygame # 렌더링용
import numpy as np
import gym
# FrozenLake 환경 생성
env = gym.make("FrozenLake-v1", is_slippery=False)
state, _ = env.reset()
print("FrozenLake 환경 정상 작동")
gym 소스코드에서 np.bool8을 np.bool_로 수동 수정할 수 있습니다.gym 패키지 경로는 다음 명령어로 확인 가능합니다:
pip show gym
설치된 경로로 이동해 gym 관련 파일을 열고, np.bool8을 np.bool_로 변경합니다.
이 방법은 이후 패키지 업데이트 시 다시 문제가 발생할 수 있으므로 권장하지 않습니다.