Python 3.7.0 and Ansible 2.6 : ModuleNotFoundError: No module named '_curses'

Python 3.7.0 and Ansible 2.6 : ModuleNotFoundError: No module named '_curses'

ModuleNotFoundError:当 运行 一个 ansible 剧本时,没有看到名为 '_curses' 的模块错误。我需要 pip 安装某些特定模块吗?

File "/path/python/lib/python3.7/site-packages/ansible/plugins/action/pause.py", line 41, in <module>
import curses
File "/path/python/lib/python3.7/curses/__init__.py", line 13, in <module>
from _curses import *

错误的另一个例子:

Python 3.7.0
[GCC 7.3.0] on linux 
Type "help", "copyright", "credits" or "license" for more information.
>>> import curses
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/python3/lib/python3.7/curses/__init__.py", line 13, in <module>
    from _curses import *
  ModuleNotFoundError: No module named '_curses'
>>>

出现此错误是因为在编译 Python3 源时系统中未安装 curses。因此解决方案如下:

首先安装curses:

sudo apt-get install libncurses-dev
sudo apt-get install libncursesw5-dev 

(我没关注libncursesw5-dev,如果libncurses-dev安装的话可能是多余的)

然后,从源构建 Python。

Python 3.7.0
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.  
>>> import curses

现在没有错误,Ansible playbook 运行了!