1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MacにpyenvでPython環境をつくる

Posted at

###実施環境
Mac: OS X El Capitan
Shell: zsh (.zshrc にsource ~/.bash_profile)

公式のインストール手順に従う
pyenv公式(github)

今回は、homebrewで物臭せずに**Basic GitHub Checkout**方式で行う

##pyenvをgithubからclone

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

##環境変数を定義(pyenvにパスを通す)

$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile

##pyenv initを適用する設定
shimsとautocompletionを有効にするため。
※shims: プログラムのバージョン間の差異を埋める緩衝材のように使うもの
 →参考:Shimの意味

echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
  • $(pyenv init -)は、PATHを操作してPATHの先頭に$(pyenv root)/shims:を追加する
  • そのため、この記述は.bash_profileの末尾に記述する必要がある →詳しくは、Understanding Shims
  • echo -e: エスケープシーケンスを解釈する
  • command -v <cmd>: commandに指定された文字列をコマンドとして扱った場合のコマンドパスを出力
  • eval : stringsをコマンドとして実行する。この場合、$(pyenv init -)の結果が実行される

##Shellを再起動

$ exec "$SHELL"

これで、pyenvが利用可能になる。

$ pyenv install 2.7.8

##pyenvの使い方
参照: pyenv Command Reference

1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?