我正在尝试安装 pyautogui。它有一些错误,如下所示:
File "<pyshell#2>", line 1, in <module>
display = Display()
File "/usr/lib/python3.5/site-packages/Xlib/display.py", line 89, in __init__
self.display = _BaseDisplay(display)
File "/usr/lib/python3.5/site-packages/Xlib/display.py", line 71, in __init__
protocol_display.Display.__init__(self, *args, **keys)
File "/usr/lib/python3.5/site-packages/Xlib/protocol/display.py", line 160, in __init__
raise error.DisplayConnectionError(self.display_name, r.reason)
Xlib.error.DisplayConnectionError: Can't connect to display ":0": b'No protocol specified\n'
然后我用谷歌搜索,发现一些专家发现了一些错误:
https://github.com/LiuLang/python3-xlib/issues/6 https://github.com/LiuLang/python3-xlib/issues/7
所以他们通过更改 Xlib 中 xauth.py 的代码来解决它。当我关注它时,它引发了另一个错误,如下所示:
File "<pyshell#2>", line 1, in <module>
display = Display()
File "/usr/lib/python3.5/site-packages/Xlib/display.py", line 89, in __init__
self.display = _BaseDisplay(display)
File "/usr/lib/python3.5/site-packages/Xlib/display.py", line 71, in __init__
protocol_display.Display.__init__(self, *args, **keys)
File "/usr/lib/python3.5/site-packages/Xlib/protocol/display.py", line 92, in __init__
name, host, displayno)
File "/usr/lib/python3.5/site-packages/Xlib/support/connect.py", line 101, in get_auth
return mod.get_auth(sock, dname, host, dno)
File "/usr/lib/python3.5/site-packages/Xlib/support/unix_connect.py", line 124, in new_get_auth
return au.get_best_auth(family, addr, dno)
File "/usr/lib/python3.5/site-packages/Xlib/xauth.py", line 112, in get_best_auth
address = address.encode()
AttributeError: 'bytes' object has no attribute 'encode'
你有没有遇到过类似的问题?还是因为我的系统有问题?
(稍后编辑)
我只是尝试在 python2.7.12 中执行所有操作,但遇到了以下错误消息:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
display = Display()
File "/usr/lib/python2.7/site-packages/Xlib/display.py", line 89, in __init__
self.display = _BaseDisplay(display)
File "/usr/lib/python2.7/site-packages/Xlib/display.py", line 71, in __init__
protocol_display.Display.__init__(self, *args, **keys)
File "/usr/lib/python2.7/site-packages/Xlib/protocol/display.py", line 92, in __init__
name, host, displayno)
File "/usr/lib/python2.7/site-packages/Xlib/support/connect.py", line 101, in get_auth
return mod.get_auth(sock, dname, host, dno)
File "/usr/lib/python2.7/site-packages/Xlib/support/unix_connect.py", line 121, in new_get_auth
au = xauth.Xauthority()
File "/usr/lib/python2.7/site-packages/Xlib/xauth.py", line 47, in __init__
raise error.XauthError('~/.Xauthority: %s' % err)
XauthError: ~/.Xauthority: [Errno 2] No such file or directory: '/home/rnie/.Xauthority'
你遇到过这个问题吗?.Xauthority 默认应该在我的用户主目录下,对吧?我无法通过检查“cat ~/.Xauthority”找到它。它说没有这样的文件:(