LoginSignup
33
31

More than 5 years have passed since last update.

OSX Yosemiteでpython動作環境を設定した(pyenv + pip)

Last updated at Posted at 2014-12-07

1) pyenvをインストール
brew install pyenv

2) pyenvのrehashを自動化するプラグインをインストール
brew install pyenv-pip-rehash

3) シェルの起動スクリプトにpyenvの情報を追記 (bashの場合はzshの部分を置換)
echo 'export PYENV_ROOT="${HOME}/.pyenv"' >> ~/.zshrc
echo 'if [ -d "${PYENV_ROOT}" ]; then' >> ~/.zshrc
echo ' export PATH=${PYENV_ROOT}/bin:$PATH' >> ~/.zshrc
echo ' eval "$(pyenv init -)"' >> ~/.zshrc
echo 'fi' >> ~/.zshrc
exec $SHELL -l

4) pyenvで特定のバージョンのpythonをインストール
pyenv install 3.4.2

5) 特定のディレクトリにおけるpythonのversionを決定する
pyenv local 3.4.2

6) easy_installでpipをインストール
sudo easy_install pip

7) 確認 (step5でversionを決定したディレクトリで)
which python
/Users/Owner/.pyenv/shims/python

python --version
Python 3.4.2

which easy_install
/Users/Owner/.pyenv/shims/easy_install

easy_install --version
setuptools 2.1

pip --version
pip 1.5.6 from /Users/Owner/.pyenv/versions/3.4.2/lib/python3.4/site-packages (python 3.4)

以下分かりづらかったところ
1) easy_installは、pipを使う場合pipのインストール時にしか使わない。
Windowsを買って、最初にIEでChromeを入れてからはIE使わないみたいなもの。
なぜなら、pipはeasy_installの一部置換版であるため。

2) pipインストール時、sudoを付けないとpermission deniedと言われる。rootが必要なディレクトリを触るため。

33
31
1

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
33
31