pyenv virtualenv 3.5.2 xxxxxした環境で、import cursesしたらおこられた

1
2
3
4
5
6
7
$ python test.py
Traceback (most recent call last):
File "test.py", line 4, in <module>
import curses
File "/home/username/.anyenv/envs/pyenv/versions/3.5.2/lib/python3.5/curses/__init__.py", line 13, in <module>
from _curses import *
ImportError: No module named '_curses'

調べた

The C modules of Python is not a script file and it must not work even if you just copy it. You must rebuild the Python and modules against system’s curses library.
The lack of library or development headers of curses (e.g. libncursesw5-dev) might causes those issues. Please confirm if you have enough package for the module.

という事なので、pythonの再構築が必要らしい

再構築

1
2
3
4
5
6
7
// cursesのライブラリ類インストール
$ sudo apt-get install libncurses5 libncurses5-dev libncursesw5

// install済みの物を1回削除して再構築
$ pyenv uninstall 3.5.2
$ pyenv install 3.5.2
$ pyenv virtualenv 3.5.2 xxxxx