Python3 未在交互模式下出现

Python3 未在交互模式下出现

我在工作计算机上安装了 python3。

Python 3.4.3 (default, May  3 2016, 09:46:33) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.

交互式编辑器无法工作。例如,我无法使用 emacs 控制序列。我只是显示“^A”,而不是转到行首。

这里提到了这个功能:

https://docs.python.org/3.4/tutorial/interactive.html

它说:

Some versions of the Python interpreter support editing of the 
current input line and history substitution, similar to facilities 
found in the Korn shell and the GNU Bash shell. This is implemented 
using the GNU Readline library, which supports various styles of 
editing. 

文档没有说明需要启用此功能、哪些版本的 Python 解释器支持编辑,或者构建过程中是否存在某些问题(假设 Python3 是从源代码构建的),导致 GNU Readline 库无法工作。而且,我在谷歌上搜索了很多,看看如何解决这个问题,但没有运气。

奇怪的是,同一台机器上安装了Python 2,并且它支持交互式编辑。而且,我家用机器上安装的 Python 3 也运行得很好。

答案1

我是研究这个问题的技术人员,并找到了如何进行交互式编辑的方法。通过 yum 的问题是,由于操作系统使用了太多的 python,我们无法通过 yum 更新它(公司政策)。

我必须编译 python 3.4.3来源。编译并安装后,我必须添加每个缺少的包。这个特殊的包是gnureadline。 Readline 已弃用。以下是我构建和安装该软件包的步骤(适用于 CentOS 6.7):

  1. wget https://pypi.python.org/pypi/gnureadline/6.3.3
  2. tar -xzvf gnureadline-6.3.3.tar.gz
  3. cd gnureadline-6.3.3
  4. python3 setup.py install

    笔记: 在这里我遇到了一个问题/usr/bin/ld: cannot find –lncurses。使用/usr/bin/ld –lncurses --verbose发现它正在搜索的路径没有库。创建了一个符号链接并且它起作用了。如果没有收到错误,请跳到最后一步。

  5. ln -s /lib64/libncurses.so.5.7 /usr/lib64/libncurses.so

  6. python3 setup.py install
  7. 已验证我可以使用ctrl-a和 箭头键在行中移动。

相关内容