pyenv
- pyenvは、シンプルなPythonバージョン管理のためのツールです。
- 2系、3系や3系のマイナーバージョンでの管理が楽。
pyenvをインストールする上で必要なライブラリをインストールする
pyenvをインストールするときに必要なそのほかのライブラリは下記を参照する。 各環境のインストール方法は下記を参照すると乗ってます。 github.com
alpineの場合、下記のライブラリをインストールする
apk add --no-cache git bash build-base libffi-dev openssl-dev bzip2-dev zlib-dev readline-dev sqlite-dev
pyenvのインストール
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
pyenvのパスを通す
- alpineの場合、下記のような設定になる
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.ashrc echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.ashrc
- alpineでパスがうまく通らない場合下記のページを参考にする github.com stackoverflow.com
Docker
- dockerfileは下記のように記載する
FROM alpine:latest RUN apk update RUN apk add --no-cache git bash build-base libffi-dev openssl-dev bzip2-dev zlib-dev readline-dev sqlite-dev ENV ENV="/root/.ashrc" RUN git clone https://github.com/pyenv/pyenv.git ~/.pyenv RUN echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.ashrc RUN echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.ashrc
docker-compose
version: '3' services: backend: container_name: backend build: context: ./ dockerfile: ./containers/backend/Dockerfile environment: - TZ=Asia/Tokyo ports: - "8000:8000" tty: true
動作確認
# docker-compose build # docker-compose up -d # docker exec -it backend /bin/ash # pyenv pyenv 1.2.19-6-gbdfed51d Usage: pyenv <command> [<args>] Some useful pyenv commands are: --version Display the version of pyenv commands List all available pyenv commands exec Run an executable with the selected Python version global Set or show the global Python version(s) help Display help for a command hooks List hook scripts for a given pyenv command init Configure the shell environment for pyenv install Install a Python version using python-build local Set or show the local application-specific Python version(s) prefix Display prefix for a Python version rehash Rehash pyenv shims (run this after installing executables) root Display the root directory where versions and shims are kept shell Set or show the shell-specific Python version shims List existing pyenv shims uninstall Uninstall a specific Python version version Show the current Python version(s) and its origin version-file Detect the file that sets the current pyenv version version-name Show the current Python version version-origin Explain how the current Python version is set versions List all Python versions available to pyenv whence List all Python versions that contain the given executable which Display the full path to an executable