简体   繁体   English

如何在Fedora 27上安装PyAutoGUI

[英]How to install PyAutoGUI on Fedora 27

When I run 当我跑步

sudo pip3 install PyAutoGUI

I receive the following error 我收到以下错误

[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/

I have followed other troubleshooting advice by installing Pillow and Display and using just the pip command. 我通过安装Pillow和Display并仅使用pip命令来遵循其他疑难解答建议。

I have also attempted installation of PyAutoGUI by cloning the package from GitHub and installing that way, however the following error message is returned: 我还尝试通过从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'

I am following the instructions from Chapter 18 of Automate the Boring Stuff with the commands slightly altered to suit Fedora 27 Workstation. 我正在按照《自动化无聊的东西》第18章中的说明进行操作,并略微更改了一些命令以适合Fedora 27工作站。

This answer is tested on Fedora 30. 该答案已在Fedora 30上进行了测试。

First install dependencies 首次安装依赖项

sudo dnf install scrot
sudo dnf install python3-tkinter
sudo dnf install python3-devel.x86_64

Then install PyAutoGUI with pip (without sudo/root) 然后用pip(没有sudo / root)安装PyAutoGUI

pip3 install --user python3-xlib
pip3 install --user pyautogui

Note: PyAutoGUI seems to require X, which is not default in Ferodra 30, but can be chosen at the login screen. 注意:PyAutoGUI似乎需要X,这在Ferodra 30中不是默认值,但可以在登录屏幕上选择。 Look for Xorg. 寻找Xorg。

(Side note: When installing software, it is recommended to use sudo, if you are logged on as root, there is no need for sudo) (附带说明:安装软件时,建议使用sudo,如果您以root用户身份登录,则无需sudo。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM