【问题标题】:How to get readline working with python in alpine如何让 readline 在 alpine 中使用 python
【发布时间】:2016-09-03 03:56:14
【问题描述】:

当我在运行 alpine 发行版的 Docker 容器中 apk add python3 时,像 Ctrl <left arrow> 这样的组合键,而不是按整个单词移动光标,而是打印这样的内容(在这里,我输入了“垃圾邮件鸡蛋”,然后按住控制并按左箭头键):

Python 3.5.1 (default, Dec  9 2015, 14:41:32) 
[GCC 5.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> spam ham;5D

仅仅apk adding readline 或pip3 installing 本身并不能解决问题。

如何让 readline 在这种环境中使用 python?

【问题讨论】:

    标签: python docker readline alpine


    【解决方案1】:

    看起来关键在于让 readline 正常工作,但您可能还必须正确处理您的 TERM。

    我试过这样的 Dockerfile:

    FROM alpine
    RUN apk update && \
      apk add python3 python3-dev build-base ncurses-dev bash && \
      python3 -m ensurepip && \
      pip3 install readline
    
    COPY ./inputrc /etc/inputrc
    

    使用来自https://github.com/frol/docker-alpine-env/blob/master/etc/inputrc 的 inputrc,复制如下:

    # do not bell on tab-completion
    #set bell-style none
    
    set meta-flag on
    set input-meta on
    set convert-meta off
    set output-meta on
    
    $if mode=emacs
    
    # for linux console and RH/Debian xterm
    "\e[1~": beginning-of-line
    "\e[4~": end-of-line
    "\e[5~": beginning-of-history
    "\e[6~": end-of-history
    "\e[7~": beginning-of-line
    "\e[3~": delete-char
    "\e[2~": quoted-insert
    "\e[5C": forward-word
    "\e[5D": backward-word
    "\e\e[C": forward-word
    "\e\e[D": backward-word
    "\e[1;5C": forward-word
    "\e[1;5D": backward-word
    
    # for rxvt
    "\e[8~": end-of-line
    
    # for non RH/Debian xterm, can't hurt for RH/DEbian xterm
    "\eOH": beginning-of-line
    "\eOF": end-of-line
    
    # for freebsd console
    "\e[H": beginning-of-line
    "\e[F": end-of-line
    $endif
    

    以下是我收集此信息的几个链接:

    NB - 我知道安装 bash 似乎很愚蠢,但没有它 pip3 install readline 会失败。必须安装 gcc 等也不理想,但如果您需要 apk del-ing 一些事情,您可以在此之后进行清理。

    所有这些都准备好后,它在我的 mac 上运行,但不能立即在 putty 上运行,尽管我怀疑只是 TERM 设置,YMMV。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 2019-02-09
      • 2019-05-23
      • 2016-10-27
      • 2012-11-25
      • 1970-01-01
      相关资源
      最近更新 更多