0

This is my first time working with machine learning libraries, I used to make it all myself, and when I did it worked, but I guess that when everyone tells you not to do the job yourself and let the libraries do it for you, you eventually try, and I tried "gym" of OpenAI on python, my code is very simple(I found it on a youtube video that explains how to use this library since I had no idea what I am getting into)

    import gym

env = gym.make("MountainCar-v0")
env.reset()

done = False

while not done:
    action = 2
    newState, reward, done, _ = env.step(action)
    env.render()

env.close()

this code returns me this error:

Traceback (most recent call last): File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet__init__.py", line 378, in getattr return getattr(self._module, name) AttributeError: 'NoneType' object has no attribute 'get_default'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:/Users/user/PycharmProjects/TestOnGymLibrary/me/RoeeHerzovich/TestOnGymLibrary

/Core.py", line 11, in env.render() File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\gym\core.py", line 235, in render return self.env.render(mode, **kwargs) File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\gym\envs\classic_control\mountain_car.py", line 78, in render from gym.envs.classic_control import rendering File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\gym\envs\classic_control\rendering.py", line 27, in from pyglet.gl import * File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\gl__init__.py", line 239, in import pyglet.window File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\window__init__.py", line 1896, in gl._create_shadow_window() File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\gl__init__.py", line 208, in _create_shadow_window _shadow_window = Window(width=1, height=1, visible=False) File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\window\win32__init__.py", line 134, in init super(Win32Window, self).init(*args, **kwargs) File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\window__init__.py", line 501, in init display = get_platform().get_default_display() File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\window__init__.py", line 1845, in get_default_display return pyglet.canvas.get_display() File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\canvas__init__.py", line 77, in get_display from pyglet.app import displays File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\app__init__.py", line 175, in event_loop = EventLoop() File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\app\base.py", line 119, in init self.clock = clock.get_default() File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet__init__.py", line 384, in getattr import(import_name) File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\clock.py", line 166, in _default_time_function = time.clock AttributeError: module 'time' has no attribute 'clock'

I tried looking in places for this, but I haven't seen that... I have gym, matplotlib and pyglet installed, I checked them and I even tried to --upgrade them and it said it is already upgraded, so I don't know what is going on. Can anyone please help me with it?

I appreciate all of your comments :)

1Mangomaster1
  • 190
  • 3
  • 11
  • i think you will have to find and check code for `"MountainCar-v0"` and see why `render()` expect some extra argument. – furas Jan 14 '20 at 21:54
  • Oh damn, that means digging deep into openAI's gym library.... oof... this is why I hate being dependent on libraries and prefer doing things on my own... I'll look into it, or at least, I'll try, thanks for the suggestion – 1Mangomaster1 Jan 14 '20 at 21:57

2 Answers2

0

The true error comes from the bottom of the trace you posted:

_default_time_function = time.clock AttributeError: module 'time' has no attribute 'clock'

This error has been addressed here.

Options:

Find where time.clock() is being called, and change it to time.perf_counter()

Downgrade to 3.7

Greg
  • 1,595
  • 2
  • 9
  • 20
  • I have changed time.clock to time.pref_counter() and it raised a different error: >line 251, in __init__ self.next_ts = self.time() >TypeError: 'float' object is not callable – 1Mangomaster1 Jan 14 '20 at 22:03
0

Except for the time.perf_counter() there was another thing that needed to be changed. I have written it all in here. Thanks to everyone who helped me here

Answer:

Class: Clock.py Row: 166 old: _default_time_function = time.clock changed to: _default_time_function = time.perf_counter()

Class: Clock.py Row: 251 old: self.next_ts = self.time() changed to: self.next_ts = self.time

1Mangomaster1
  • 190
  • 3
  • 11