サクッとamazon linuxにpyenvとpython3を導入 | www.yoshiislandblog.net

サクッとamazon linuxにpyenvとpython3を導入

既に何度も書いている気もするが、再掲
サクッとAmazon Linuxにpyenv+python3.5の環境を作成する

sshでログイン

%  ssh -i api-server.pem ec2-user@{IP}

必要パッケージを入れて、git clone

sudo yum install gcc gcc-c++ make git openssl-devel bzip2-devel zlib-devel readline-devel sqlite-devel

git clone https://github.com/yyuu/pyenv.git ~/.pyenv

環境変数を追記しておく

# cat ~/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

#### pyenvここから追加 ###
export PYENV_ROOT=$HOME/.pyenv
export PATH=$PYENV_ROOT/bin:$PATH
eval "$(pyenv init -)"
#### pyenvここまで ######

読み込み

# source ~/.bash_profile

pyenvが無事にインストールできたと確認

# pyenv
pyenv 1.2.2-6-g694b551
Usage: pyenv <command> [<args>]

Some useful pyenv commands are:
   commands    List all available pyenv commands
   local       Set or show the local application-specific Python version
   global      Set or show the global Python version
   shell       Set or show the shell-specific Python version
   install     Install a Python version using python-build
   uninstall   Uninstall a specific Python version
   rehash      Rehash pyenv shims (run this after installing executables)
   version     Show the current Python version and its origin
   versions    List all Python versions available to pyenv
   which       Display the full path to an executable
   whence      List all Python versions that contain the given executable

See `pyenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/pyenv/pyenv#readme

現状を確認

# pyenv versions
* system (set by /root/.pyenv/version)

python3.5をインストール

# pyenv install 3.5.0

インストールされたことを確認

# pyenv versions
* system (set by /root/.pyenv/version)
  3.5.0

3.5に環境を変更

# pyenv local 3.5.0

確認

# pyenv versions
  system
* 3.5.0 (set by /root/.python-version)

%d bloggers like this: