LoginSignup
1
8

More than 5 years have passed since last update.

pyenv の導入の巻

Last updated at Posted at 2018-07-18

目的

Pythonの2系と3系を使って開発を進めたい

目標

pyenv を導入して、2系と3系を切り替えて使う
今回は、GCP CentOS7 にはデフォルトでpython2 系が入っているため、pyenv へ python 3 を導入する

作業

ライブラリの更新

sudo yum -y update

git と pyenv 前提ソフトの導入

sudo yum -y install gcc wget curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker autoconf bzip2 bzip2-devel libbz2-dev openssl openssl-devel readline readline-devel

git を導入

下のサイトを参照
https://qiita.com/hatakkkk/items/c06dd493d0fc96f7468d

これを入力するんだ
wget https://www.kernel.org/pub/software/scm/git/git-2.9.5.tar.gz

tar vfx git-2.9.5.tar.gz

cd git-2.9.5

make configure

./configure --prefix=/usr

make all

sudo make install

pyenv の導入

下のコマンドを入力するんだ
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
source .bash_profile

導入できたか確認する
pyenv -v

pyenv 1.2.6

pyenv を更新する
pyenv update

一旦、VM の再起動
sodo reboot

python の導入可能ver を確認する
pyenv install --list

今回は、3.6.6 を導入
pyenv install 3.6.6

pyenv のリフレッシュ
pyenv rehash

現行のpython ver を表示
python --version

Python 2.7.5

3.代を使いたいので、導入した python 3.6.6 へ変更する。
pyenv global 3.6.6

再度、python ver を確認
python --version

Python 3.6.6

これで完了!
お疲れ様でした。

Tips

warning 出た

Downloading Python-3.6.6.tar.xz...
-> https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tar.xz
Installing Python-3.6.6...
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?
WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib?
Installed Python-3.6.6 to /home/h1d34h4t/.pyenv/versions/3.6.6

必要なものをインストールして完了。
sudo yum -y install bzip2 bzip2-devel libbz2-dev openssl openssl-devel readline readline-devel

1
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
8