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

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


Solution 1:[1]

I had the same error trying to run a python file using pyautogui from crontab on my Ubuntu 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 this option was not available on log in. If you are in the same predicament you could try enabling Wayland protocol from /etc/gdm3/custom.conf

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 betweem them entails. Good luck!

Solution 2:[2]

Did you perform pip3 install pyautogui as a root user?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 twotoomanytomato
Solution 2 Friedlguana