LoginSignup
8
9

More than 5 years have passed since last update.

CentOS上にPython3.7をインストールする(pyenv)

Last updated at Posted at 2018-11-10

概要

CentOS7上にpyenvを使ってpython 3.7.1をインストールしようとしたら、module不足のエラーが発生しました。
本記事では、エラー内容とその解消方法を記載しています。

環境

  • CentOS 7.5.1804 (Core)
  • kernel 3.10.0-862.14.4.el7.x86_64
  • pyenv 1.2.8

Pythonインストールまでにやったこと

  • pyenvのインストールと環境変数のセットアップ
$ sudo yum -y install git
$ git clone https://github.com/yyuu/pyenv.git ~/.pyenv
$ vi ~/.bash_profile
# 以下を追記する。
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

$ . ~/.bash_profile
  • 必要なパッケージのインストール
$ sudo yum -y install xz bzip2 sqlite-devel gcc openssl-devel readline-devel zlib-devel

Python3.7インストール

$ /bin/bash -lc "pyenv install 3.7.1 && pyenv rehash && pyenv global 3.7.1"
Downloading Python-3.7.1.tar.xz...
-> https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz
Installing Python-3.7.1...

BUILD FAILED (CentOS Linux 7 using python-build 1.2.8)

Inspect or clean up the working tree at /tmp/python-build.20181110073538.3811
Results logged to /tmp/python-build.20181110073538.3811.log

Last 10 log lines:
    import pip._internal
  File "/tmp/tmp295z_qwe/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/__init__.py", line 42, in <module>
  File "/tmp/tmp295z_qwe/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/cmdoptions.py", line 16, in <module>
  File "/tmp/tmp295z_qwe/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/index.py", line 25, in <module>
  File "/tmp/tmp295z_qwe/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/download.py", line 39, in <module>
  File "/tmp/tmp295z_qwe/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/utils/glibc.py", line 3, in <module>
  File "/tmp/python-build.20181110073538.3811/Python-3.7.1/Lib/ctypes/__init__.py", line 7, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
make: *** [install] Error 1

以下のモジュールが存在しないとのエラーが出力されました。

ModuleNotFoundError: No module named '_ctypes'

解消方法

libffi-develをインストールしてあげれば解決しました。

$ sudo yum -y install libffi-devel

python3.7.1再インストール。

$ /bin/bash -lc "pyenv install 3.7.1 && pyenv rehash && pyenv global 3.7.1"
Downloading Python-3.7.1.tar.xz...
-> https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz
Installing Python-3.7.1...
WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib?
Installed Python-3.7.1 to /home/vagrant/.pyenv/versions/3.7.1

$ pyenv versions
  system
* 3.7.1 (set by /home/vagrant/.pyenv/version)

無事成功。

参考

2019/1/13追記

  • Ubuntuの場合

libffi-develに相当するパッケージはlibffi-dev。

$ sudo apt-get install libffi-dev
8
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
9