1
2

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.

pyenv のインストールと version の切り替え

Last updated at Posted at 2019-02-28

mac に ansible を入れようとしたら pip が依存している python の version に言及があった。

$ sudo pip install ansible

DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
The directory '/Users/<あなたのお名前>/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/<あなたのお名前>/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

バージョンを上げれば解決しそうだが、pyenv を入れたほうが良さそうである。
https://github.com/pyenv/pyenv

install

$ brew update
$ brew install pyenv

お好きな python の version をインストール

$ pyenv install --list

$ pyenv install 2.7.15

バージョンが変わったか確認

$ pyenv global 3.7.2
  system
* 3.7.2 (set by /Users/<あなたのお名前>/.pyenv/version)

$ python --version
Python 2.7.10 

変わっとらんがな😫😫😫

環境変数PATHを修正

$PATH に pyenv の作業ディレクトリの shims へのパスを通す必要がある。
https://github.com/pyenv/pyenv#understanding-path

Understanding Shims
pyenv works by inserting a directory of shims at the front of your PATH:
$(pyenv root)/shims:/usr/local/bin:/usr/bin:/bin

ということで、 ~/.config/fishconfig.fish に下記を追加。

# pyenv
set -x PATH (pyenv root)/shims $PATH

リロード

$ source ~/.config/fish/config.fish

再度確認

$ python --version
Python 3.7.2

$ which python
/Users/<あなたのお名前>/.pyenv/shims/python

うぇーい😺😺😺

おわり

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?