pyenv+anaconda python実行環境構築やってみた!
前段
参画しているプロジェクトでpythonを利用することになったので、環境構築の手順をメモしてみました。
目的
vagrant + virtual boxで作ったcentOS7.2上に+ pyenv + anacondaでpython実行環境を構築する。
VM作成
centOS7.2
box追加
$ vagrant box add centOS7.2 https://github.com/CommanderK5/packer-centos-template/releases/download/0.7.2/vagrant-centos-7.2.box
VagrantFile初期化
$ vagrant init centOS7.2
起動!!
$ vagrant up
SSH接続
$ vagrant ssh [vagrant@localhost ~]$ #ssh成功!!
gitインストール
$ sudo yum install git ~~略~~ # 途中インストールしてもいいか聞かれるのでyと答える。 Installed: git.x86_64 0:1.8.3.1-14.el7_5 ~~略~~ Complete! #wow!
VMにpython環境構築
pyenv導入
pyenv本体
$ git clone git://github.com/yyuu/pyenv.git ~/.pyenv
プラグイン
$ git clone https://github.com/yyuu/pyenv-pip-rehash.git ~/.pyenv/plugins/pyenv-pip-rehash
コマンドの位置を教える
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc $ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc $ echo 'eval "$(pyenv init -)"' >> ~/.bashrc $ source ~/.bashrc
確認
$ pyenv # コマンドのヘルプが出る。 pyenv 1.2.7-1-g7190216 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
anacondaインストール
Anaconda(python3系)のバージョンを確認する。
$ pyenv install -l | grep anaconda3 anaconda3-2.0.0 anaconda3-2.0.1 anaconda3-2.1.0 anaconda3-2.2.0 anaconda3-2.3.0 anaconda3-2.4.0 anaconda3-2.4.1 anaconda3-2.5.0 anaconda3-4.0.0 anaconda3-4.1.0 anaconda3-4.1.1 anaconda3-4.2.0 anaconda3-4.3.0 anaconda3-4.3.1 anaconda3-4.4.0 anaconda3-5.0.0 # 今回はコイツをインストールする。 anaconda3-5.0.1 anaconda3-5.1.0 anaconda3-5.2.0
Anaconda(5.0.0)インストール
$ pyenv install anaconda3-5.0.0 # 結構時間かかるので、コーヒーでも淹れて待つ。 Downloading Anaconda3-5.0.0.1-Linux-x86_64.sh... -> https://repo.continuum.io/archive/Anaconda3-5.0.0.1-Linux-x86_64.sh Installing Anaconda3-5.0.0.1-Linux-x86_64... Installed Anaconda3-5.0.0.1-Linux-x86_64 to /home/vagrant/.pyenv/versions/anaconda3-5.0.0 # yeah!!
デフォルト環境として設定する。
$ pyenv global anaconda3-5.0.0
コマンドの位置を教える。
$ echo 'export PATH="$PYENV_ROOT/versions/anaconda3-5.0.0/bin:$PATH"' >> ~/.bashrc $ source ~/.bashrc
確認
$ python --version Python 3.6.2 :: Anaconda, Inc. # excellent!!!
後語り
意外とカンタン!