Get_screenshot_as_png() errors with Wayland

When I try to call get_screenshot_as_png(chart) with bokeh 1.3.4, I get this stack trace:

   chartImage = get_screenshot_as_png(chart)
  File "/home/rotten/.virtualenvs/myvenv/lib/python3.7/site-packages/bokeh/io/export.py", line 217, in get_screenshot_as_png
    web_driver = driver if driver is not None else webdriver_control.get()
  File "/home/rotten/.virtualenvs/myvenv/lib/python3.7/site-packages/bokeh/io/webdriver.py", line 116, in get
    self.current = self.create()
  File "/home/rotten/.virtualenvs/myvenv/lib/python3.7/site-packages/bokeh/io/webdriver.py", line 121, in create
    return create_phantomjs_webdriver()
  File "/home/rotten/.virtualenvs/myvenv/lib/python3.7/site-packages/bokeh/io/webdriver.py", line 75, in create_phantomjs_webdriver
    phantomjs_path = detect_phantomjs()
  File "/home/rotten/.virtualenvs/myvenv/lib/python3.7/site-packages/bokeh/util/dependencies.py", line 117, in detect_phantomjs
    raise RuntimeError('Error encountered in PhantomJS detection: %r' % out[1].decode('utf8'))
RuntimeError: Error encountered in PhantomJS detection: 'Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.\n'

I’ve tried setting QT_QPA_PLATFORM as an environment variable before running my python script. It did not help. I tried setting it to both “wayland” and to “offscreen”. I’m stumped as to what it is trying to tell me to do to work around the issue.

FWIW, I’m running Ubuntu 19.04 - Disco Dingo.

I can run export_png() without any problems, so for now I’ll export the chart to a file, and then read it back in with Image.open(). I’d love to be able to just go straight to an image object directly.

I’m afraid I don’t really have any clue what this could be about. It’s especially confusing to me that you say export_png works fine, because the very first line of code in export_png is nothing but a call to get_screenshot_as_png

Can you think of any differences at all between the situation when you run with export_png and when you try with get_screenshot_as_png?

The only difference is when I call export_png() I pass it the file name and an explicit webdriver. I just tried passing that same webdriver argument to get_screenshot_as_png() and it didn’t help (same error).

browserOpts = ChromeOptions()
browserOpts.add_argument('--headless')
browserOpts.add_argument("--window-size=2000x2000")
web_driver = Chrome(options=browserOpts)

chartImage = get_screenshot_as_png(chart, webdriver=web_driver)

vs

export_png(chart, tmpImgFileName, webdriver=web_driver)
chartImage = Image.open(tmpImgFileName)

aha!

get_screenshot_as_png() uses “driver” not ‘webdriver’ like export_png().

Now it works! Thanks!

chartImage = get_screenshot_as_png(chart, driver=web_driver)
1 Like

Ah :confused: That’s an unfortunate inconsistency, especially given get_screenshot_as_png accepts **kwargs. Glad you figured it out!