Problems importing python-Xlib

前端 未结 8 710
暖寄归人
暖寄归人 2021-02-07 07:39

I installed a new module and it appears as if one of its dependencies was not already installed. The module is called Xlib.display. Here is the error message I received:

相关标签:
8条回答
  • 2021-02-07 08:16

    Please try.

    This shall install Xlib sudo apt-get install python-xlib

    Then you can check

    >>from Xlib.display import Display

    To install PyMouse if you want to control and capture mouse events please use:

    sudo easy_install https://github.com/pepijndevos/PyMouse/zipball/master

    0 讨论(0)
  • 2021-02-07 08:16

    I honestly cant explain why this works... but here is the command that got it working for me.

    sudo apt-get install python3-xlib
    

    Should not work because xlib apparently does not work with python 3.x, but everything installed alright, so I'm not complaining!

    0 讨论(0)
  • 2021-02-07 08:23

    I was looking for the same answer, however after some more digging it seems that XCB (X protocol C-language Binding) will obsolete Xlib in general. From the XCB website:

    The X protocol C-language Binding (XCB) is a replacement for Xlib featuring a small footprint, latency hiding, direct access to the protocol, improved threading support, and extensibility.

    Fortunately there are python bindings available as python-xpyb in apt or xpyb on PyPi. I've not gotten that far in my project so I haven't tested if this works with Python3, but this is probably the way to go and the proper place to file any Python3 support bugs if necessary.

    0 讨论(0)
  • 2021-02-07 08:27

    On Debian systems install python-xlib.

    On other systems there's a high probability that the package carries the same name.

    0 讨论(0)
  • 2021-02-07 08:27

    Scenario:

    I was trying to use screenshot functionalities of pyautogui package. I was getting this error:

    Traceback (most recent call last):
      File "test_screenshot.py", line 1, in <module>
        import pyautogui
      File ".../miniconda3/envs/myenv/lib/python3.7/site-packages/pyautogui/__init__.py", line 152, in <module>
        from . import _pyautogui_x11 as platformModule
      File ".../miniconda3/envs/myenv/lib/python3.7/site-packages/pyautogui/_pyautogui_x11.py", line 7, in <module>
        from Xlib.display import Display
    ModuleNotFoundError: No module named 'Xlib'
    

    Python code (test_screenshot.py):

    import pyautogui
    img = pyautogui.screenshot('test.png')
    

    Environment:

    • Ubuntu 16.04 (LTS)
    • conda 4.5.11
    • Python 3.7 (Miniconda)
    • requirements.txt:

      certifi==2019.3.9
      Pillow==5.4.1
      PyAutoGUI==0.9.42
      PyGetWindow==0.0.4
      PyMsgBox==1.0.6
      PyRect==0.1.4
      PyScreeze==0.1.20
      PyTweening==1.0.3
      

    Solution:

    I installed python-xlib package in the conda environment using:

    pip install python-xlib
    

    Now test_screenshot.py is running without any error.

    Updated requirements.txt:

    certifi==2019.3.9
    Pillow==5.4.1
    PyAutoGUI==0.9.42
    PyGetWindow==0.0.4
    PyMsgBox==1.0.6
    PyRect==0.1.4
    PyScreeze==0.1.20
    python-xlib==0.25
    PyTweening==1.0.3
    six==1.12.0
    
    0 讨论(0)
  • 2021-02-07 08:29

    I was having the same problem, but the solutions above didn't work for me. Since I had installed python through the anaconda package, when I used:

    sudo apt-get install  python-xlib
    

    Xlib was still undetectable by python2. The solution in my case was to use:

    anaconda search -t conda python-xlib
    

    Then find the package from the anaconda api, mine was erik/python-xlib. Install it using:

    conda install --channel https://conda.anaconda.org/erik python-xlib
    

    Then it worked.

    0 讨论(0)
提交回复
热议问题