Froth on the Daydream

Technology, Music and so on

Install Python 3 to Amazon Linux

I installed Python 3 to Amazon Linux because default version was 2.7.12 on Amazon Linux.(Sep 2017)

 

Try apt-get

$ sudo apt-get install python3

sudo: apt-get: command not found

Oops.. 

https://forums.aws.amazon.com/thread.jspa?threadID=72398

 

Install the tool "pyenv"

It seems I can manage versions by this tool.

 

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

$ sudo git clone https://github.com/yyuu/pyenv.git /usr/bin/.pyenv
$ cd /usr/bin/.pyenv
$ sudo mkdir shims
$ sudo mkdir versions

$ sudo chown -R ec2-user .pyenv

 

Add below on "~/.bashrc".

export PYENV_ROOT="/usr/bin/.pyenv"
if [ -d "${PYENV_ROOT}" ]; then
export PATH=${PYENV_ROOT}/bin:$PATH
eval "$(pyenv init -)"
fi

 

$ source ~/.bashrc

 

Install Python3

List version options I can install.

$ pyenv install --list

 

Install

$ pyenv install 3.6.2

 

Change version

$ pyenv global 3.6.2
$ python -V
Python 2.7.12

 

... uh-oh??

What's wrong??

 

I tried again by reference to below web page.

pyenvのインストール、使い方、pythonのバージョン切り替えできない時の対処法 - Qiita

 

$ which python
/usr/bin/.pyenv/shims/python

Not wrong...

 

I challenged again by reference to below web page.

pythonのバージョンが切り替わらない - Qiita

 

add below on "~/.bash_profile"

export PATH="$HOME/.pyenv/shims:$PATH"

 

$ source ~/.bash_profile
$ pyenv global 3.6.2
$ python --version
Python 3.6.2

 

Gotcha!!