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!

2 Likes

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?

1 Like

The same problem here.

1 Like

Same problem… any suggestion?

1 Like

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

1 Like

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

1 Like

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

1 Like

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

1 Like

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.

1 Like

Same problem here.

1 Like

@Hamilton_T_Silva, hi, I had the similar problem. I have tried to run RemoteMouse via systemd and soultion for me:

File: remote-mouse.service
───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ [Unit]
2 │ Description=Remote mouse
3 │
4 │ [Service]
5 │ ExecStart=/home/$USER/bin/remotemouse/RemoteMouse
6 │ ExecStop=kill $(pgrep RemoteMouse)
7 │ User=$USER
8 │ Environment=DISPLAY=:1
9 │
10 │ [Install]
11 │ WantedBy=default.tagret

2 Likes

Thanks for sharing.

1 Like