Import pautogui and KeyError: ‘display’

I have an app that runs fine in local host but when deploying I get error message

2021-12-15 01:22:56.871 Uncaught app exception
Traceback (most recent call last):
File “/home/appuser/venv/lib/python3.7/site-packages/streamlit/script_runner.py”, line 354, in _run_script
exec(code, module.dict)
File “/app/staygreen/main.py”, line 28, in
import pyautogui as gui
File “/home/appuser/venv/lib/python3.7/site-packages/pyautogui/init.py”, line 249, in
import mouseinfo
File “/home/appuser/venv/lib/python3.7/site-packages/mouseinfo/init.py”, line 223, in
_display = Display(os.environ[‘DISPLAY’])
File “/usr/local/lib/python3.7/os.py”, line 681, in getitem
raise KeyError(key) from None
KeyError: ‘DISPLAY’

Thanks for the help!

1 Like

Same here. I am able to use pyautogui to print screenshot in my localhost but it doesn’t work in the streamlit app. Looks like streamlit is not accepting the pyautogui module.

Is there any other ways I can add a screenshot button in streamlit, since a report function hasn’t been developed yet?

The same problem here.

Same problem… any suggestion?

I don’t think you can use pyautogui in a headless environment. What would be the point anyway?

I am trying to control the mouse on the screen. Locally is working OK.

That is the problem, when you deploy to streamlit cloud your python code runs in a virtual machine with no mouse and no screen.

Uhn… there is a way to pass the control to browser?

This is programming, there is a way to almost everything. But I don’t know what it can be. Certainly not as easy as just using pyautogui.

Same problem here.