在 termux 中安装 pynput 时出现错误

问题描述 投票:0回答:3

我正在尝试在 Termux 中安装 pynput 以便能够运行我的 python 脚本。 当我尝试 [as in the attached screenshot]

pip install pynput
时,我收到此错误消息:

ERROR: Command errored out with exit status 1:
     command: /data/data/com.termux/files/usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/data/data/com.termux/files/usr/tmp/pip-install-f07stt3a/evdev_9d15119a1c774b69be29371e48a8012d/setup.py'"'"'; __file__='"'"'/data/data/com.termux/files/usr/tmp/pip-install-f07stt3a/evdev_9d15119a1c774b69be29371e48a8012d/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /data/data/com.termux/files/usr/tmp/pip-record-u2bumfem/install-record.txt --single-version-externally-managed --compile --install-headers /data/data/com.termux/files/usr/include/python3.9/evdev
         cwd: /data/data/com.termux/files/usr/tmp/pip-install-f07stt3a/evdev_9d15119a1c774b69be29371e48a8012d/
    Complete output (37 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-aarch64-3.9
    creating build/lib.linux-aarch64-3.9/evdev
    copying evdev/__init__.py -> build/lib.linux-aarch64-3.9/evdev
    copying evdev/device.py -> build/lib.linux-aarch64-3.9/evdev
    copying evdev/ecodes.py -> build/lib.linux-aarch64-3.9/evdev
    copying evdev/eventio.py -> build/lib.linux-aarch64-3.9/evdev
    copying evdev/eventio_async.py -> build/lib.linux-aarch64-3.9/evdev
    copying evdev/events.py -> build/lib.linux-aarch64-3.9/evdev
    copying evdev/evtest.py -> build/lib.linux-aarch64-3.9/evdev
    copying evdev/ff.py -> build/lib.linux-aarch64-3.9/evdev
    copying evdev/genecodes.py -> build/lib.linux-aarch64-3.9/evdev
    copying evdev/uinput.py -> build/lib.linux-aarch64-3.9/evdev
    copying evdev/util.py -> build/lib.linux-aarch64-3.9/evdev
    running build_ext
    running build_ecodes
    The 'linux/input.h' and 'linux/input-event-codes.h' include files
    are missing. You will have to install the kernel header files in
    order to continue:

        yum install kernel-headers-$(uname -r)
        apt-get install linux-headers-$(uname -r)
        emerge sys-kernel/linux-headers
        pacman -S kernel-headers

    In case they are installed in a non-standard location, you may use
    the '--evdev-headers' option to specify one or more colon-separated
    paths. For example:

        python setup.py \
          build \
          build_ecodes --evdev-headers path/input.h:path/input-event-codes.h \
          build_ext --include-dirs  path/ \
          install
    ----------------------------------------
ERROR: Command errored out with exit status 1: /data/data/com.termux/files/usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/data/data/com.termux/files/usr/tmp/pip-install-f07stt3a/evdev_9d15119a1c774b69be29371e48a8012d/setup.py'"'"'; __file__='"'"'/data/data/com.termux/files/usr/tmp/pip-install-f07stt3a/evdev_9d15119a1c774b69be29371e48a8012d/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /data/data/com.termux/files/usr/tmp/pip-record-u2bumfem/install-record.txt --single-version-externally-managed --compile --install-headers /data/data/com.termux/files/usr/include/python3.9/evdev Check the logs for full command output.

我不知道下一步该做什么。 请帮忙。

python-3.x linux command-line pynput termux
3个回答
2
投票

由于 Termux 没有 evdev 所需的 kernel header 文件,您会收到错误。如果没有它,就不可能安装 pynput 和其他需要 evdev 的模块。 关于您关于安装命令的问题,错误消息已包含它:

    yum install kernel-headers-$(uname -r)
    apt-get install linux-headers-$(uname -r)
    emerge sys-kernel/linux-headers
    pacman -S kernel-headers

但不要尝试

我并不是说会发生不好的事情。它就是行不通。 Termux 的存储库中没有内核头文件,据我所知,无风险安装它们的唯一选择是使用 proot。所以你需要这样做:

apt update # Update package repositor(y|ies)
apt upgrade # Upgrade everything just in case
apt install proot # Install **proot**
apt install proot-distro # [OPTIONAL] Install official (made by Termux's developer) proot installer

如果您安装了 proot-distro,则执行以下操作:

proot-distro list # List current available distros
然后

  1. 安装你想要的发行版
  2. 开始吧
  3. 使用该发行版的安装命令再次安装 python(以及您需要的内容),因为 proot 就像虚拟机
  4. 安装内核头文件。 根据您的原始发行版选择命令
  5. 奔跑
    pip install pynput

2
投票

我在为不同的包安装 evdev 时遇到相同的错误消息(quantconnect 的“lean”);安装先决条件解决了这个问题。从 手册页 (我引用 debian 但选择你的发行版):

可以从以下位置安装最新稳定版本的 python-evdev pypi,前提是你有 gcc/clang、pip 以及 Python 和 Linux 安装在您的系统上的开发标头。安装它们是 分布特定,通常属于以下之一 类别:

   On a Debian compatible OS:

      $ apt-get install python-dev python-pip gcc
      $ apt-get install linux-headers-$(uname -r)

0
投票

几十年来,Unix 文本和键盘事件处理在curses 和ncurses 中得到了很好的处理,并且可以在Termux 中的python 中运行。只要您缩小 Termux 窗口(捏合缩小),此示例就可以工作,这样在移动光标时就不会遇到边界错误。

https://medium.com/explorations-in-python/an-introduction-to-curses-in-python-7686b9641190

import curses


def main():

    """
    The curses.wrapper function is an optional function that
    encapsulates a number of lower-level setup and teardown
    functions, and takes a single function to run when
    the initializations have taken place.
    """

    curses.wrapper(curses_main)


def curses_main(w):

    """
    This function is called curses_main to emphasise that it is
    the logical if not actual main function, called by curses.wrapper.
    Its purpose is to call several other functions to demonstrate
    some of the functionality of curses.
    """

    w.addstr("-----------------\n")
    w.addstr("| codedrome.com |\n")
    w.addstr("| curses demo   |\n")
    w.addstr("-----------------\n")
    w.refresh()

    printing(w)

    moving_and_sleeping(w)

    colouring(w)

    w.addstr("\npress any key to exit...")
    w.refresh()
    w.getch()


def printing(w):

    """
    A few simple demonstrations of printing.
    """

    w.addstr("This was printed using addstr\n\n")
    w.refresh()

    w.addstr("The following letter was printed using addch:- ")
    w.addch('a')
    w.refresh()

    w.addstr("\n\nThese numbers were printed using addstr:-\n{}\n{:.6f}\n".format(123, 456.789))
    w.refresh()


def moving_and_sleeping(w):

    """
    Demonstrates moving the cursor to a specified position before printing,
    and sleeping for a specified period of time.
    These are useful for very basic animations.
    """

    row = 5
    col = 0

    curses.curs_set(False)

    for c in range(65, 91):

        w.addstr(row, col, chr(c))
        w.refresh()
        row += 1
        col += 1
        curses.napms(100)

    curses.curs_set(True)

    w.addch('\n')


def colouring(w):

    """
    Demonstration of setting background and foreground colours.
    """

    if curses.has_colors():

        curses.init_pair(1, curses.COLOR_YELLOW, curses.COLOR_RED)
        curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_GREEN)
        curses.init_pair(3, curses.COLOR_MAGENTA, curses.COLOR_CYAN)

        w.addstr("Yellow on red\n\n", curses.color_pair(1))
        w.refresh()

        w.addstr("Green on green + bold\n\n", curses.color_pair(2) | curses.A_BOLD)
        w.refresh()

        w.addstr("Magenta on cyan\n", curses.color_pair(3))
        w.refresh()

    else:

        w.addstr("has_colors() = False\n");
        w.refresh()


main() 
© www.soinside.com 2019 - 2024. All rights reserved.