Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'FigureCanvasMac' object has no attribute 'renderer' #47

Closed
brunoaibanez opened this issue Dec 18, 2020 · 3 comments
Closed

Comments

@brunoaibanez
Copy link

I am trying to use it in Mac Catalina 10.15.7. I followed the steps to execute demo.py, after installing FF by the Mac link provided.

I did the make, and exported Environment variable to FF/ff path. However, when executing demo.py it shows the following error:

  File "hellopddlgym.py", line 6, in <module>
    img = env.render()
  File "/Users/bruno/Documents/pddlgym/pddlgym/core.py", line 446, in render
    return self._render(self._state.literals, *args, **kwargs)
  File "/Users/bruno/Documents/pddlgym/pddlgym/rendering/sokoban.py", line 167, in render
    return render_from_layout(layout, get_token_images)
  File "/Users/bruno/Documents/pddlgym/pddlgym/rendering/utils.py", line 64, in render_from_layout
    im = fig2data(fig, dpi=dpi)
  File "/Users/bruno/Documents/pddlgym/pddlgym/rendering/utils.py", line 19, in fig2data
    data = np.fromstring(fig.canvas.tostring_argb(), dtype=np.uint8, sep='')
  File "/Users/bruno/Library/Python/3.7/lib/python/site-packages/matplotlib/backends/backend_agg.py", line 440, in tostring_argb
    return self.renderer.tostring_argb()
AttributeError: 'FigureCanvasMac' object has no attribute 'renderer'
@tomsilver
Copy link
Owner

Hi, thanks for checking out pddlgym and for filing the issue! It looks like this issue may be related to matplotlib's backend. Would you mind trying adding this line to the very top of your script (make sure it's the first thing) and see if that resolves the issue?

import matplotlib; matplotlib.use('agg')

@brunoaibanez
Copy link
Author

brunoaibanez commented Dec 18, 2020 via email

@tomsilver
Copy link
Owner

Hi Bruno, glad to hear that resolved the error! Yes, that sounds like expected behavior. If you'd like to see the images that are produced, you could try out the "hello world" example from the README:

import pddlgym
import imageio

env = pddlgym.make("PDDLEnvSokoban-v0")
obs, debug_info = env.reset()
img = env.render()
imageio.imsave("frame1.png", img)
action = env.action_space.sample(obs)
obs, reward, done, debug_info = env.step(action)
img = env.render()
imageio.imsave("frame2.png", img)

That example should save two images in your current directory (frame1.png and frame2.png).

Thanks again for raising the issue. We'll update the README with a note on matplotlib. Feel free to reopen if anything else arises.

steinjohannes added a commit to steinjohannes/picasso that referenced this issue Jul 23, 2022
Using functionalities in Render on macOS (M1, Monterey) that generate a canvas with visual output (e.g. 'filter picks by locs') produces the following error: AttributeError: 'FigureCanvasMac' object has no attribute 'renderer'.

Adding the line 'matplotlib.use('agg')' fixes this (e.g. described here tomsilver/pddlgym#47)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants