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

asdfでPythonだけパスが通ってない時

Last updated at Posted at 2025-03-10

環境

  • Apple M2 Max
  • macOS Sequoia 15.3.1
-> % asdf --version
asdf version 0.16.5
-> % zsh --version
zsh 5.9 (x86_64-apple-darwin21.3.0)

Pythonだけasdfじゃないんすけど

バージョン管理ツールasdfにPython、Ruby、nodeを入れて使っています。ところが。

-> % which ruby
/Users/saitoh/.asdf/shims/ruby
-> % which node
/Users/saitoh/.asdf/shims/node

-> % which python
python: aliased to python3
-> % which python3
/usr/local/bin/python3
-> % python --version
Python 3.13.2
-> % python3 --version
Python 3.13.2

brewで入れたPythonを読んでしまっている……

whereコマンド使ってみる

-> % where ruby
/Users/saitoh/.asdf/shims/ruby
/Users/saitoh/.asdf/shims/ruby
/usr/bin/ruby

-> % where python3
/usr/local/bin/python3
/usr/bin/python3

asdfが当たっていないことがわかった。

.zshrcにPATH追記

.zshrcを開くよ


-> % vi ~/.zshrc

export PATH="$HOME/.asdf/shims:$PATH" を追記

:wqで保存して、

-> % source ~/.zshrc

PATHを~/.zshrcに追加したので、sourceコマンドで再読み込み、どうよ

-> % which python3
/usr/local/bin/python3

ち〜ん(笑)

.asdf/shims/を見にいく

rubyとnodeはちゃんとasdfが読まれてるんだよな。じゃあ、.asdf/shimsを見に行けば、何かわかるかもしれない。

.asdf/shims/ruby
#!/usr/bin/env bash
# asdf-plugin: ruby 3.2.1
# asdf-plugin: ruby 3.1.2
exec asdf exec "ruby" "$@"

ふむ。pythonはっと…

ん?.asdf/shims/pythonがなく、代わりに.asdf/shims/python3.13ってのがある。

.asdf/shims/python3.13
#!/usr/bin/env bash
# asdf-plugin: python 3.13.2
exec asdf exec "python3.13" "$@"

え、ってことはもしかして…

-> % which python3.13 
/Users/saitoh/.asdf/shims/python3.13

なるほどね。ってことは、.asdf/shims/pythonってのを作ってあげて、同様の内容を書けばいいのでは?

-> % touch .asdf/shims/python
-> % vi .asdf/shims/python

以下を追記

.asdf/shims/python
#!/usr/bin/env bash
# asdf-plugin: python 3.13.2
exec asdf exec "python" "$@"

これでどうよ

-> % which python3
/usr/local/bin/python3

ち〜ん(笑)

.zshrcのaliasコメントアウト

.zshrcをもう一度見直す

pythonコマンドはそもそもaliasを入れている

~/.zshrc
# Python3のalias
alias python='python3'
alias pip='pip3'

あ、これじゃね?
#alias python='python3'とコメントアウトして、exec $SHELL -lで再起動

-> % which python
/Users/saitoh/.asdf/shims/python

やったぜ。

まとめ

  • .asdf/shims/pythonが無かったのと、~/.zshrcに書いたaliasが原因だった。
  • aliasでpython→python3を読みにいく→python3の場所は
    /usr/local/bin/python3。これで、asdfのpythonが読まれなかった。

追記(asdfのpluginを入れ直す)

  • その後、.asdf/shims/pythonが再度消える現象が発生した。
  • そもそも、asdfのpluginをアンインストール→インストールして、入れ直せばよかった。
-> % asdf plugin remove python # プラグイン削除
-> % asdf plugin add python # プラグイン追加
-> % asdf install python 3.13.2 # LTSのPythonをインストール
-> % asdf set -u python 3.13.2 # グローバルで使えるように設定
-> % which python
/Users/saitoh/.asdf/shims/python

参考にしたページ

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