python - 运行 pyautogui.size() 时出现 "Xlib.xauth: warning, no xauthority details available"

标签 python ubuntu xlib pyautogui

我使用的是 Ubuntu,我安装了 pyautoguipip3 install pyautogui ,并且成功了。但是,当我运行此代码时:

import pyautogui
pyautogui.size()
它给了我这个错误:
Xlib.xauth: warning, no xauthority details available
Xlib.xauth: warning, no xauthority details available

最佳答案

我在尝试使用 crontab 中的 pyautogui 运行 python 文件时遇到了同样的错误;桌面 Ubuntu 20.04。对我有用的是激活“Wayland”显示协议(protocol)。这可以通过单击齿轮图标从登录屏幕轻松完成。
我现在在另一个 Ubuntu 系统上,注意到登录时没有 Wayland 选项。如果您还注意到登录时没有 Wayland 选项,您可以尝试从/etc/gdm3/custom.conf 启用 Wayland 协议(protocol) >> 在以下链接中解释...
Wayland 和 Xorg 解释:
https://linuxiac.com/xorg-x11-wayland-linux-display-servers-and-protocols-explained/
如何启用和禁用 Wayland:
https://linuxconfig.org/how-to-enable-disable-wayland-on-ubuntu-22-04-desktop
免责声明:
我是 Linux 新手,这对我有用,但我不了解这些不同显示协议(protocol)的细微差别,或者它们之间的切换需要什么。祝你好运!
如果仍然无法正常工作:
您可以创建一个 .sh 文件来启动您的 python 文件,在顶部添加 shebang。如果您需要激活 venv,请执行此操作。然后添加 XAUTHORITY。然后当然最后,用 python 启动你的文件。

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

关于python - 运行 pyautogui.size() 时出现 "Xlib.xauth: warning, no xauthority details available",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63440490/

相关文章:

C++ 和 XGrabKeyboard 键盘锁定

python - 具有自动标签功能的标签堆叠条

python - 正则表达式替换 Python 中奇数重复出现的字符

shell - .Sh脚本在特定位置安装java

php - 无法在 Ubuntu 上使用 PHP 和 ODBC 连接到 SQL Anywhere 12

x11 - C、Xlib 中的 freedesktop XEmbed 系统托盘客户端代码

c - 如何在 X11 中使用修改键从 KeyPress 和 KeyRelease 事件中获取虚拟键代码

python - Keras LSTM 中隐藏状态的含义

python - Scrapy 与多处理兼容吗?

php - Linux - 我无法更改 NTFS 分区的其他读取或执行权限