pip install xxxx で Command errored out with exit status 1 … のエラーが出たとき

Pythonpyenv,Python

※本投稿では pyenv を使って Python のバージョンを管理している環境を例とします。

pip3 install xxxx

上記のコマンドを実行して下記のようなエラーが出たとき

Collecting xxxx
...中略
        from _ctypes import Union, Structure, Array
    ModuleNotFoundError: No module named '_ctypes'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

一旦 Python をアンインストール

pyenv uninstall 3.x.x

libffi をインストール

sudo yum install libffi-devel

再び python をインストール

python install 3.x.x

以上の操作を行ったあとに再度 pip3 install コマンドを実行してみてください。