如何让readline与高山的python一起工作
当我apk add python3
在运行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 add
readline
或pip3 install
它本身并不能解决问题。
如何在这个环境中使用python读取readline?
看起来像这个关键主要是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
这里有几个链接,我收集了这些信息:
- 按下python shell中的箭头键时看到转义字符
- https://docs.python.org/2/tutorial/interactive.html
- Bash CTRL在单词/string之间移动光标
NB – 我知道似乎安装bash似乎愚蠢,但pip3 install readline
失败,没有它。 也不是理想的安装海湾合作委员会等,虽然你可以清理之后,如果你需要通过apk del
一些东西。
有了这一切,它在我的Mac上工作,但不是立即在腻子,虽然我怀疑只是TERM设置,YMMV。