当我跑步时
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'
我遵循自动化闷热东西第18章的说明,其命令稍有改动,以适应Fedora 27工作站。
答案 0 :(得分:0)
此答案已在Fedora 30上进行了测试。
首次安装依赖项
sudo dnf install scrot
sudo dnf install python3-tkinter
sudo dnf install python3-devel.x86_64
然后使用pip(没有sudo / root)安装PyAutoGUI
pip3 install --user python3-xlib
pip3 install --user pyautogui
注意: PyAutoGUI似乎需要X,这在Ferodra 30中不是默认值,但可以在登录屏幕上选择。寻找Xorg。
(注意:安装软件时,建议使用sudo,如果您以root用户身份登录,则不需要sudo)