DEV Community

Reishi Mitani
Reishi Mitani

Posted on

Creating a Python3 Environment Using Pyenv in EC2

First, you need git.

$ sudo yum install git
// type yes to all questions
$ git version
git version 2.23.3
Enter fullscreen mode Exit fullscreen mode

Then install pyenv by cloning from GitHub.

git clone https://github.com/yyuu/pyenv.git ~/.pyenv
Enter fullscreen mode Exit fullscreen mode

Create the paths for pyenv.

$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
$ source ~/.bash_profile

// Check if the paths are created correctly.
$ pyenv -v
pyenv 1.2.20-5-g1ec3c6f1
Enter fullscreen mode Exit fullscreen mode

Install the necessary dependencies.

sudo yum install gcc zlib-devel bzip2 bzip2-devel readline readline-devel sqlite sqlite-devel openssl openssl-devel libffi-devel -y
Enter fullscreen mode Exit fullscreen mode

Install python.

$ pyenv install 3.7.0
// This will take several minutes to complete
Enter fullscreen mode Exit fullscreen mode

Choose 3.7.0 as the global version.

$ pyenv global 3.7.0
$ pyenv rehash
$ python --version
3.7.0
Enter fullscreen mode Exit fullscreen mode

References

EC2サーバにPython3環境構築
pyenvで3.7系のインストールに失敗したときのメモ

Sorry, only Japanese versions are available.

Top comments (0)