pyenvでpythonをインストールしようとしたらエラーが出たけど解決した

記事内に商品プロモーションを含む場合があります。
2022.12.22 1941 views

環境

エラーの内容

pyenv を使って ptyhon をインストール。

pyenv install 3.11.1

そうすると次のようなエラーが吐き出されてインストールに失敗した。

Downloading Python-3.11.1.tar.xz...
-> https://www.python.org/ftp/python/3.11.1/Python-3.11.1.tar.xz
Installing Python-3.11.1...
WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib?
WARNING: The Python readline extension was not compiled. Missing the GNU readline lib?
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

Please consult to the Wiki page to fix the problem.
https://github.com/pyenv/pyenv/wiki/Common-build-problems


BUILD FAILED (Ubuntu 20.04 using python-build 2.3.9-1-gff93c58b)

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

Last 10 log lines:
                $ensurepip --root=/ ; \
fi
Looking in links: /tmp/tmpxh4rt0h4
Processing /tmp/tmpxh4rt0h4/setuptools-65.5.0-py3-none-any.whl
Processing /tmp/tmpxh4rt0h4/pip-22.3.1-py3-none-any.whl
Installing collected packages: setuptools, pip
  WARNING: The scripts pip3 and pip3.11 are installed in '/home/mst/.anyenv/envs/pyenv/versions/3.11.1/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  NOTE: The current PATH contains path(s) starting with `~`, which may not be expanded by all applications.
Successfully installed pip-22.3.1 setuptools-65.5.0

解決方法

こちらの内容を参考にする。

https://github.com/pyenv/pyenv/wiki#suggested-build-environment

私の環境は Ubuntu なのでこのコマンドを実行。

sudo apt update; sudo apt install build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev curl llvm \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev libsasl2-dev python3-dev libldap2-dev

もう一度、pyenv で python のインストールを行い無事に成功。

pyenv install 3.11.1
Downloading Python-3.11.1.tar.xz...
-> https://www.python.org/ftp/python/3.11.1/Python-3.11.1.tar.xz
Installing Python-3.11.1...
Installed Python-3.11.1 to /home/mst/.anyenv/envs/pyenv/versions/3.11.1

関連記事