"Xlib.xauth: warning, no xauthority details available" when running pyautogui.size()

Viewed 1052

I'm using Ubuntu, and I installed pyautogui with pip3 install pyautogui, and it was successful. However, when I ran this code:

import pyautogui
pyautogui.size()

It gave me this error:

Xlib.xauth: warning, no xauthority details available
Xlib.xauth: warning, no xauthority details available
2 Answers

I had the same error trying to run a python file using pyautogui from crontab; Desktop Ubuntu 20.04. What worked for me was activating "Wayland" display protocol. This was easily done from the log-in screen by clicking the gear icon.

I am now on a different Ubuntu system, and noticed that Wayland option was not available on log in. If you also notice there is no Wayland option on log in, you could try enabling Wayland protocol from /etc/gdm3/custom.conf >> Explained in the following links...

Wayland and Xorg Explained: https://linuxiac.com/xorg-x11-wayland-linux-display-servers-and-protocols-explained/

How to Enable and Disable Wayland: https://linuxconfig.org/how-to-enable-disable-wayland-on-ubuntu-22-04-desktop

Disclaimer: I am new to Linux, and this worked for me, but I do not understand the nuances of these different display protocols, or what switching between them entails. Good luck!

If Still Not Working:

You could make a .sh file to launch your python file, add shebang at the top.. If you need to activate venv, do that next. Then add XAUTHORITY. Then of course at the end, launch your file with python.

#!bin/bash
source /venv/bin/activate
XAUTHORITY=/run/user/1000/gdm/Xauthority
python3 /path_to_dir/myfile.py

Did you perform pip3 install pyautogui as a root user?

Related