LoginSignup
0
1

More than 1 year has passed since last update.

Homebrewで管理していたPythonをpyenv移行する。(覚書)

Posted at

目的

ローカルでPythonの開発環境を整備するため。

背景

Homebrewで管理していたPythonを使用していると、poetryで利用するPythonのバージョンと合わなくなってしまった。また、pyenvを利用して、ローカルやグローバルののPythonのバージョンを変更しようとしてもHomebrewでインストールしたPythonを優先して参照していた。
そのため、Homebrewを使用したグローバルでのPythonをアンインストールし、pyenvに環境を移行させる。

環境(現状把握)

以下、Pythonのバージョンとpyenvを利用してバージョンを確認した際の挙動を記述する。

% brew deps python --tree     
python@3.9
├── gdbm
├── mpdecimal
├── openssl@1.1
│   └── ca-certificates
├── readline
├── sqlite
│   └── readline
└── xz

試しに一つ、アンインストールして挙動を確認する。

% brew uninstall gdbm
Error: Refusing to uninstall /usr/local/Cellar/gdbm/1.23
because it is required by aws-elasticbeanstalk, aws-sam-cli, awscli, glib, imagemagick, libheif, liblqr, poetry, python@3.10, python@3.8, python@3.9 and shared-mime-info, which are currently installed.
You can override this and force removal with:
  brew uninstall --ignore-dependencies gdbm

pythonを削除してみようとする。

% brew uninstall python
Error: Refusing to uninstall /usr/local/Cellar/python@3.9/3.9.12
because it is required by awscli, glib, imagemagick, libheif, liblqr and shared-mime-info, which are currently installed.
You can override this and force removal with:
  brew uninstall --ignore-dependencies python

依存関係でuninstall出来なさそう。そのため、上記一覧のものを削除していく。試しに一つだけアンインストールしてみる。

% brew uninstall awscli
Uninstalling /usr/local/Cellar/awscli/2.5.4... (12,600 files, 100.8MB)
% brew uninstall python
Error: Refusing to uninstall /usr/local/Cellar/python@3.9/3.9.12
because it is required by glib, imagemagick, libheif, liblqr and shared-mime-info, which are currently installed.

依存関係が一つ消えてそうです。なので、消していきます。

% brew uninstall imagemagick
Uninstalling /usr/local/Cellar/imagemagick/7.1.0-29... (804 files, 28.7MB)
% brew uninstall python     
Error: Refusing to uninstall /usr/local/Cellar/python@3.9/3.9.12
because it is required by glib, libheif, liblqr and shared-mime-info, which are currently installed.
% brew uninstall liblqr 
Uninstalling /usr/local/Cellar/liblqr/0.4.2_1... (25 files, 174.0KB)
% brew uninstall glib  
Error: Refusing to uninstall /usr/local/Cellar/glib/2.72.0
because it is required by shared-mime-info, which is currently installed.
You can override this and force removal with:
  brew uninstall --ignore-dependencies glib

消さないといけない順番がありそう。ひとまず、glibはとばす。

% brew uninstall libheif
Uninstalling /usr/local/Cellar/libheif/1.12.0_1... (25 files, 2.8MB)
% brew uninstall python 
Error: Refusing to uninstall /usr/local/Cellar/python@3.9/3.9.12
because it is required by glib and shared-mime-info, which are currently installed.
% brew uninstall shared-mime-info
Uninstalling /usr/local/Cellar/shared-mime-info/2.1... (86 files, 4.5MB)
% brew uninstall glib            
Uninstalling /usr/local/Cellar/glib/2.72.0... (449 files, 20.4MB)
% brew uninstall python
Uninstalling /usr/local/Cellar/python@3.9/3.9.12... (3,113 files, 55.8MB)
yuji@shiraiyujinoMBP homebrew-python-pyenv % python --version
Python 3.8.2

前のpythonのバージョンが残っている。。

最終的には以下のqitaの記事を参考にすることで、pythonのバージョンが正常に反映されました。
https://qiita.com/minarai/items/297aec329f2f029bee10

~/.zshrc
eval "$(pyenv init --path)"

参考

依存関係の確認
https://qiita.com/shge/items/39e0e5cd83642c5d4add

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