Reputation: 51
I am trying to use stable_baselines, but any model I try to use gives me the same error:
module 'gym.logger' has no attribute 'MIN_LEVEL'
I have attached an example from their website that is giving me the same error. I tried looking online but haven't had any success. Also, I am currently using Conda to create my environment with the following settings.
Tensorflow: 1.15.0 Python: 3.7.11
code bellow.
import gym
from stable_baselines.common.policies import MlpPolicy
from stable_baselines.common import make_vec_env
from stable_baselines import PPO2
# multiprocess environment
env = make_vec_env('CartPole-v1', n_envs=4)
model = PPO2(MlpPolicy, env, verbose=1)
model.learn(total_timesteps=25000)
model.save("ppo2_cartpole")
del model # remove to demonstrate saving and loading
model = PPO2.load("ppo2_cartpole")
# Enjoy trained agent
obs = env.reset()
while True:
action, _states = model.predict(obs)
obs, rewards, dones, info = env.step(action)
env.render()
Full error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/var/folders/2l/c0wfhk2x0qz3v_6x0ylvvdr00000gn/T/ipykernel_4323/1825670659.py in <module>
8 env = make_vec_env('CartPole-v1', n_envs=4)
9
---> 10 model = PPO2(MlpPolicy, env, verbose=1)
11 model.learn(total_timesteps=25000)
12 model.save("ppo2_cartpole")
~/miniconda3/envs/tf15/lib/python3.7/site-packages/stable_baselines/ppo2/ppo2.py in __init__(self, policy, env, gamma, n_steps, ent_coef, learning_rate, vf_coef, max_grad_norm, lam, nminibatches, noptepochs, cliprange, cliprange_vf, verbose, tensorboard_log, _init_setup_model, policy_kwargs, full_tensorboard_log, seed, n_cpu_tf_sess)
95
96 if _init_setup_model:
---> 97 self.setup_model()
98
99 def _make_runner(self):
~/miniconda3/envs/tf15/lib/python3.7/site-packages/stable_baselines/ppo2/ppo2.py in setup_model(self)
108
109 def setup_model(self):
--> 110 with SetVerbosity(self.verbose):
111
112 assert issubclass(self.policy, ActorCriticPolicy), "Error: the input policy for the PPO2 model must be " \
~/miniconda3/envs/tf15/lib/python3.7/site-packages/stable_baselines/common/base_class.py in __enter__(self)
1127 self.tf_level = os.environ.get('TF_CPP_MIN_LOG_LEVEL', '0')
1128 self.log_level = logger.get_level()
-> 1129 self.gym_level = gym.logger.MIN_LEVEL
1130
1131 if self.verbose <= 1:
AttributeError: module 'gym.logger' has no attribute 'MIN_LEVEL'
Upvotes: 5
Views: 4772
Reputation: 17
If you're on a Juypter notebook environment. try restarting the kernel. it worked for me.
Upvotes: -1
Reputation: 4028
I sloved this by go to :
Anaconda3\Lib\site-packages\stable_baselines\common\base_class.py
change :
self.gym_level = gym.logger.MIN_LEVEL
into :
self.gym_level = gym.logger
Upvotes: 2
Reputation: 2301
stable_baselines
does not seem to fully work with the latest gym anymore, try installing a version of gym from around 2020:
pip install "gym==0.19.0"
That said, you should try to migrate to current stable_baselines3
.
Upvotes: 2
Reputation: 11
I encountered the same problem. I manually changed all the "min_level"s in the gym.logger.py into "MIN_LEVEL"s. Or you can also change the "MIN_LEVEL" in stable_baselines.common.base_class.py into "min_level".
I guess this is an inconsistency between the new version of openai gym and stable baselines. (Using stable baselines 3 would not encounter this issue.)
Upvotes: 1
Reputation: 1351
You must update your gym module to the latest version with:
pip install gym[all] -U
in your command line
Upvotes: 0