当我跑
sudo pip3 install PyAutoGUI
我收到以下错误
[root@localhost Projects]# sudo pip install pyautogui
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip install --user` instead.
Collecting pyautogui
Using cached PyAutoGUI-0.9.36.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-ywXbn7/pyautogui/setup.py", line 6, in <module>
version=__import__('pyautogui').__version__,
File "pyautogui/__init__.py", line 115, in <module>
from . import _pyautogui_x11 as platformModule
File "pyautogui/_pyautogui_x11.py", line 7, in <module>
from Xlib.display import Display
ImportError: No module named Xlib.display
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-ywXbn7/pyautogui/
我通过安装 Pillow 和 Display 并仅使用 pip 命令遵循了其他故障排除建议。
我还尝试通过从 GitHub 克隆包并以这种方式安装来安装 PyAutoGUI,但是返回以下错误消息:
[root@localhost Projects]# git clone https://github.com/asweigart/pyautogui
Cloning into 'pyautogui'...
remote: Counting objects: 1079, done.
remote: Total 1079 (delta 0), reused 0 (delta 0), pack-reused 1079
Receiving objects: 100% (1079/1079), 2.03 MiB | 697.00 KiB/s, done.
Resolving deltas: 100% (733/733), done.
[root@localhost Projects]# cd pyautogui
[root@localhost pyautogui]# sudo python3 setup.py install
Traceback (most recent call last):
File "setup.py", line 6, in <module>
version=__import__('pyautogui').__version__,
File "/home/luke/Projects/pyautogui/pyautogui/__init__.py", line 115, in <module>
from . import _pyautogui_x11 as platformModule
File "/home/luke/Projects/pyautogui/pyautogui/_pyautogui_x11.py", line 160, in <module>
_display = Display(os.environ['DISPLAY'])
File "/usr/local/lib/python3.6/site-packages/Xlib/display.py", line 80, in __init__
self.display = _BaseDisplay(display)
File "/usr/local/lib/python3.6/site-packages/Xlib/display.py", line 62, in __init__
display.Display.__init__(*(self, ) + args, **keys)
File "/usr/local/lib/python3.6/site-packages/Xlib/protocol/display.py", line 129, in __init__
raise error.DisplayConnectionError(self.display_name, r.reason)
Xlib.error.DisplayConnectionError: Can't connect to display ":0": b'No protocol specified\n'
我按照 Automate the Boring Stuff 第 18 章中的说明操作,对命令稍作修改以适合 Fedora 27 Workstation。