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?

Visual Studio Code が Python を見つけてくれなくなった。

Posted at

ある日突然 VSCode が Python を見つけてくれなくなった。原因はいまだによくわからないがやった事を記録する。現象:

  • Python が見つからないエラーが出る。
  • 開発ディレクトリの .venv/bin/python を指定してもわけのわからないエラーが出る。(もう直ったので正確なエラーがわからない)
  • ワークスペースの settings.json に以下のように書いてみたがエラーが出る。
    • "python.defaultInterpreterPath": "myproject/.venv/bin/python",
  • うろ覚えだが ~/.rye/shims/rye を実行しようとしてエラーが出ている。
    • python コマンド (.rye/shims/python) は ~/.rye/shims/rye へのリンクになっている。

やった事

  • 多分 > Python: Set Interpreter~/.local/share/uv/python/cpython-3.11.6-macos-aarch64-none/bin/python を指定したような気がする。
  • VSCode を再起動したような気がする。
  • > Python: Set Interpreter で myproject/.venv/bin/python` が選べるようになった。

想像

  • Python environments in VS Code によれば python.defaultInterpreterPath で Python コマンドが選ばれるはワークスペースを最初に開く時だけ、次からは選んだ Python コマンドが選ばれる。
  • なので、python.defaultInterpreterPath を設定しても意味がない。
  • もしかして python のパス設定するには python コマンドの実行が必要で、なぜか現在選択中の Python コマンドが壊れたため設定できなくなったのでは?
  • 確実に動く python コマンドを設定したあと VSCode を再起動する事で 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?