mise のパス設定の不具合修正 : hkob の雑記録 (371)

はじめに

(1/6 7:40 補足: この後、brew の設定を変更することでさらに有効な手段を見つけたので、明日のブログで解説します。)

hkob の雑記録の第371回目(通算768日目)は、新しい mise のパス設定がうまく設定できなかった件を Notion AI を使って修正した件を記録しておきます。

発見のきっかけ

今日の授業で Notion API を Python から呼び出すために、requests パッケージを install しようとしていました。すると以下のようなエラーが出ました。

> python3 -m pip install requests
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try brew install
    xyz, where xyz is the package you are trying to
    install.

    If you wish to install a Python library that isn't in Homebrew,
    use a virtual environment:

    python3 -m venv path/to/venv
    source path/to/venv/bin/activate
    python3 -m pip install xyz

    If you wish to install a Python application that isn't in Homebrew,
    it may be easiest to use 'pipx install xyz', which will manage a
    virtual environment for you. You can install pipx with

    brew install pipx

    You may restore the old behavior of pip by passing
    the '--break-system-packages' flag to pip, or by adding
    'break-system-packages = true' to your pip.conf file. The latter
    will permanently disable this error.

    If you disable this error, we STRONGLY recommend that you additionally
    pass the '--user' flag to pip, or set 'user = true' in your pip.conf
    file. Failure to do this can result in a broken Homebrew installation.

    Read more about this behavior here: <https://peps.python.org/pep-0668/>

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

4月当初は homebrew でインストールした python に venv を設定していましたが、6月にゼミの学生に勧められて、mise の環境に移行していました。その時の記事はこちらです。

hkob.hatenablog.com

このエラーが出るということは、python3 が Homebrew のものになっているということです。確認してみました。

> which python3
/opt/homebrew/bin/python3

PATH 環境変数が思ったように設定されていないようです。mise のパスが設定されているにも関わらず、 /opt/homebrew/bin が先に設定されてしまっています。以前はこんなことがなかったはずです。

/Users/hkob/bin:/opt/homebrew/bin:/Users/hkob/.local/share/mise/installs/python/3.14.2/bin:/Users/hkob/.local/share/mise/installs/ruby/4.0.0/bin:/opt/homebrew/opt/mise/bin:/opt/homebrew/opt/postgresql@16/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/pmk/env/global/bin:/opt/X11/bin:/Library/Apple/usr/bin:/Library/TeX/texbin:/Applications/Wireshark.app/Contents/MacOS:/Applications/Ghostty.app/Contents/MacOS

直近でやったことは brew upgrade です。どうも update で何か余計なことをしてしまっている気がします。

原因究明

とりあえず fish の設定時に何が起こっているのかを確認してみます。ちなみに fish の設定は mackup で Dropbox で共有する形になっています。

ls -l ~/.config/fish
total 0
lrwxr-xr-x  1 hkob  staff  72 Nov 29 10:42 completions@ -> /Users/hkob/Library/CloudStorage/Dropbox/Mackup/.config/fish/completions
lrwxr-xr-x  1 hkob  staff  67 Nov 29 10:42 conf.d@ -> /Users/hkob/Library/CloudStorage/Dropbox/Mackup/.config/fish/conf.d
lrwxr-xr-x  1 hkob  staff  72 Nov 29 10:42 config.fish@ -> /Users/hkob/Library/CloudStorage/Dropbox/Mackup/.config/fish/config.fish
lrwxr-xr-x  1 hkob  staff  75 Nov 29 10:42 fish_variables@ -> /Users/hkob/Library/CloudStorage/Dropbox/Mackup/.config/fish/fish_variables
lrwxr-xr-x  1 hkob  staff  70 Nov 29 10:42 functions@ -> /Users/hkob/Library/CloudStorage/Dropbox/Mackup/.config/fish/functions

とりあえず config.fish の先頭部分を確認してみます。homebrew のパス設定は以下のようになっています。homebrew は eval 使っているのに、mise は source を使うんですね。本質的には特に大きな違いはないようですが。

# ~/.config/fish/config.fish

# homebrew
eval (/opt/homebrew/bin/brew shellenv)

# mise
/opt/homebrew/bin/mise activate fish | source

# ~/bin
set -gx PATH ~/bin $PATH

今回の件ではどうでもいいことですが、違いを気にしている質問もありました。

unix.stackexchange.com

問題は PATH がどのように変化しているのかということです。こんな時は print debug が一番簡単ですね。

# ~/.config/fish/config.fish

echo "AAAAAAAAAAAAAAAAA"
echo $PATH

# homebrew
eval (/opt/homebrew/bin/brew shellenv)

echo "BBBBBBBBBBBBBBBBBBBBB"
echo $PATH

# mise
/opt/homebrew/bin/mise activate fish | source

echo "CCCCCCCCCCCCCCCCCCCCCCCCC"
echo $PATH

set -gx PATH ~/bin $PATH

echo "DDDDDDDDDDDDDDDDDDDDDDD"
echo $PATH

この状態で、新しいターミナルを立ち上げてみます。

Last login: Mon Jan  5 20:27:18 on ttys001
AAAAAAAAAAAAAAAAA
/Users/hkob/.local/share/mise/installs/python/3.14.2/bin /Users/hkob/.local/share/mise/installs/ruby/4.0.0/bin /opt/homebrew/opt/mise/bin /opt/homebrew/opt/postgresql@16/bin /usr/local/bin /System/Cryptexes/App/usr/bin /usr/bin /bin /usr/sbin /sbin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin /opt/pmk/env/global/bin /opt/X11/bin /Library/Apple/usr/bin /Library/TeX/texbin /Applications/Wireshark.app/Contents/MacOS /Applications/Ghostty.app/Contents/MacOS
BBBBBBBBBBBBBBBBBBBBB
/opt/homebrew/bin /opt/homebrew/sbin /Users/hkob/.local/share/mise/installs/python/3.14.2/bin /Users/hkob/.local/share/mise/installs/ruby/4.0.0/bin /opt/homebrew/opt/mise/bin /opt/homebrew/opt/postgresql@16/bin /usr/local/bin /System/Cryptexes/App/usr/bin /usr/bin /bin /usr/sbin /sbin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin /opt/pmk/env/global/bin /opt/X11/bin /Library/Apple/usr/bin /Library/TeX/texbin /Applications/Wireshark.app/Contents/MacOS /Applications/Ghostty.app/Contents/MacOS
CCCCCCCCCCCCCCCCCCCCCCCCC
/opt/homebrew/bin /opt/homebrew/sbin /Users/hkob/.local/share/mise/installs/python/3.14.2/bin /Users/hkob/.local/share/mise/installs/ruby/4.0.0/bin /opt/homebrew/opt/mise/bin /opt/homebrew/opt/postgresql@16/bin /usr/local/bin /System/Cryptexes/App/usr/bin /usr/bin /bin /usr/sbin /sbin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin /opt/pmk/env/global/bin /opt/X11/bin /Library/Apple/usr/bin /Library/TeX/texbin /Applications/Wireshark.app/Contents/MacOS /Applications/Ghostty.app/Contents/MacOS
DDDDDDDDDDDDDDDDDDDDDDD
/Users/hkob/bin /opt/homebrew/bin /opt/homebrew/sbin /Users/hkob/.local/share/mise/installs/python/3.14.2/bin /Users/hkob/.local/share/mise/installs/ruby/4.0.0/bin /opt/homebrew/opt/mise/bin /opt/homebrew/opt/postgresql@16/bin /usr/local/bin /System/Cryptexes/App/usr/bin /usr/bin /bin /usr/sbin /sbin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin /opt/pmk/env/global/bin /opt/X11/bin /Library/Apple/usr/bin /Library/TeX/texbin /Applications/Wireshark.app/Contents/MacOS /Applications/Ghostty.app/Contents/MacOS
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish

そもそも、config.fish に入る前に mise の PATH が設定されていることのようです。brew upgrade で問題が発生するようになったことから、mise の設定で何か問題があるのだと考えられます。mise でインストールされるファイルを確認してみます。

brew list mise
/opt/homebrew/Cellar/mise/2025.12.13/.crates.toml
/opt/homebrew/Cellar/mise/2025.12.13/.crates2.json
/opt/homebrew/Cellar/mise/2025.12.13/bin/mise
/opt/homebrew/Cellar/mise/2025.12.13/etc/bash_completion.d/mise
/opt/homebrew/Cellar/mise/2025.12.13/lib/.disable-self-update
/opt/homebrew/Cellar/mise/2025.12.13/sbom.spdx.json
/opt/homebrew/Cellar/mise/2025.12.13/share/fish/ (2 files)
/opt/homebrew/Cellar/mise/2025.12.13/share/man/man1/mise.1
/opt/homebrew/Cellar/mise/2025.12.13/share/zsh/site-functions/_mise

fish のファイルが存在することがわかりました。この中を確認してみます。

ls -R /opt/homebrew/Cellar/mise/2025.12.13/share/fish
vendor_completions.d/ vendor_conf.d/

/opt/homebrew/Cellar/mise/2025.12.13/share/fish/vendor_completions.d:
mise.fish

/opt/homebrew/Cellar/mise/2025.12.13/share/fish/vendor_conf.d:
mise-activate.fish

vendor_conf.d の中に mise-activate.fish というファイルがあることがわかりました。明かにこれが原因のようです。中を確認すると、activate している部分がありました。MISE_FISH_AUTO_ACTIVATE を 0 にすれば activate は呼ばれないようです。

if [ "$MISE_FISH_AUTO_ACTIVATE" != "0" ]
  /opt/homebrew/opt/mise/bin/mise activate fish | source
end

Notion AI に聞いてみる

あとはこれをどのように設定すればいいかだけです。いちいち調べるのは面倒なので、Notion AI に聞いてみました。いろいろとやりとりしたので、チャット画面はゴタゴタしているのですが、最後に /save としたらいい感じに今回の問題をまとめてくれました。以下、Notion AI が作成したエージェントログの結果です。

問題

macOSでbrew install miseを使用した際、Homebrewの設定後にmise activate fishを実行してもPATHの順序が意図通りにならない。

/opt/homebrew/binmiseのパスより前に配置されてしまう。

原因

/opt/homebrew/Cellar/mise/2025.12.13/share/fish/vendor_conf.d/mise-activate.fishで自動activateが設定されているため、config.fishの実行前にmiseのパスが設定される。

if [ "$MISE_FISH_AUTO_ACTIVATE" != "0" ]
    /opt/homebrew/opt/mise/bin/mise activate fish | source
end

解決策

1. 環境変数を設定してauto activateを無効化

~/.config/fish/conf.d/00-mise.fishを作成:

set -gx MISE_FISH_AUTO_ACTIVATE 0

2. config.fish で明示的に設定

~/.config/fish/config.fishで順序を制御:

# Homebrewの設定
eval (/opt/homebrew/bin/brew shellenv)

# miseのactivate
mise activate fish | source

Fish shellの読み込み順序

  1. /etc/fish/config.fish
  2. conf.d/*.fish(システム・ユーザー両方)
  3. vendor_conf.d/*.fish
  4. ~/.config/fish/config.fish

00-プレフィックスを使用することで、vendor_conf.dより前に環境変数を設定可能。

確認方法

echo $PATH | tr ' ' '\n'

miseのパスが/opt/homebrew/binより上に表示されれば成功。

変更結果

早速 00-mise.fish を ~/.config/fish/conf.d/ の下に保存して、新規ターミナルを立ち上げました。

Last login: Mon Jan  5 20:42:09 on ttys000
AAAAAAAAAAAAAAAAA
/opt/homebrew/opt/postgresql@16/bin /usr/local/bin /System/Cryptexes/App/usr/bin /usr/bin /bin /usr/sbin /sbin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin /opt/pmk/env/global/bin /opt/X11/bin /Library/Apple/usr/bin /Library/TeX/texbin /Applications/Wireshark.app/Contents/MacOS /Applications/Ghostty.app/Contents/MacOS
BBBBBBBBBBBBBBBBBBBBB
/opt/homebrew/bin /opt/homebrew/sbin /opt/homebrew/opt/postgresql@16/bin /usr/local/bin /System/Cryptexes/App/usr/bin /usr/bin /bin /usr/sbin /sbin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin /opt/pmk/env/global/bin /opt/X11/bin /Library/Apple/usr/bin /Library/TeX/texbin /Applications/Wireshark.app/Contents/MacOS /Applications/Ghostty.app/Contents/MacOS
CCCCCCCCCCCCCCCCCCCCCCCCC
/Users/hkob/.local/share/mise/installs/python/3.14.2/bin /Users/hkob/.local/share/mise/installs/ruby/4.0.0/bin /opt/homebrew/bin /opt/homebrew/sbin /opt/homebrew/opt/postgresql@16/bin /usr/local/bin /System/Cryptexes/App/usr/bin /usr/bin /bin /usr/sbin /sbin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin /opt/pmk/env/global/bin /opt/X11/bin /Library/Apple/usr/bin /Library/TeX/texbin /Applications/Wireshark.app/Contents/MacOS /Applications/Ghostty.app/Contents/MacOS
DDDDDDDDDDDDDDDDDDDDDDD
/Users/hkob/bin /Users/hkob/.local/share/mise/installs/python/3.14.2/bin /Users/hkob/.local/share/mise/installs/ruby/4.0.0/bin /opt/homebrew/bin /opt/homebrew/sbin /opt/homebrew/opt/postgresql@16/bin /usr/local/bin /System/Cryptexes/App/usr/bin /usr/bin /bin /usr/sbin /sbin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin /opt/pmk/env/global/bin /opt/X11/bin /Library/Apple/usr/bin /Library/TeX/texbin /Applications/Wireshark.app/Contents/MacOS /Applications/Ghostty.app/Contents/MacOS
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish

which で確認してみると、無事に mise でインストールした python が立ち上がっています。

which python3
/Users/hkob/.local/share/mise/installs/python/3.14.2/bin/python3

おわりに

今回は、Notion AI で mise のパス問題を解決しました。途中のやり取りがぐちゃぐちゃしていても、自動的に会話内容をページに追加完了。ただ /save としただけで、問題・原因・解決策・確認方法を構造化して記録してくれているのが助かりますね。ここが Notion でログ管理しているいいところですね。

hkob.notion.site