前に書いた「未来の自分」が今日の私でした。
poetry のコマンドを実行しようとするとエラーが出る。下は poetry shell -vvv を実行したときのログの一部。
  Stack trace:
    ...
   3  ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/utils/env.py:1459 in _run
       1457│
       1458│             if input_:
     → 1459│                 output = subprocess.run(
       1460│                     command,
       1461│                     stdout=subprocess.PIPE,
   2  /usr/lib/python3.10/subprocess.py:501 in run
        499│         kwargs['stderr'] = PIPE
        500│
     →  501│     with Popen(*popenargs, **kwargs) as process:
        502│         try:
        503│             stdout, stderr = process.communicate(input, timeout=timeout)
   1  /usr/lib/python3.10/subprocess.py:969 in __init__
        967│                             encoding=encoding, errors=errors)
        968│
     →  969│             self._execute_child(args, executable, preexec_fn, close_fds,
        970│                                 pass_fds, cwd, env,
        971│                                 startupinfo, creationflags, shell,
  FileNotFoundError
  [Errno 2] No such file or directory: 'python'
  at /usr/lib/python3.10/subprocess.py:1845 in _execute_child
      1841│                     else:
      1842│                         err_filename = orig_executable
      1843│                     if errno_num != 0:
      1844│                         err_msg = os.strerror(errno_num)
    → 1845│                     raise child_exception_type(errno_num, err_msg, err_filename)
      1846│                 raise child_exception_type(err_msg)
      1847│
      1848│
python-is-python3 というパッケージをインストールするとうまく行くよ、という情報が散見されたが初耳のパッケージのインストールは最終手段だと思って alias をいじってみるなどして 3 時間ほどハマってたけど解決せず。結局 python-is-python3 をインストールしたらなおった。
- https://github.com/python-poetry/poetry/issues/4542
 - https://askubuntu.com/questions/1296790/python-is-python3-package-in-ubuntu-20-04-what-is-it-and-what-does-it-actually
 
と思いきや poetry install すると
Invalid PEP 440 version: '0.1.43ubuntu1'
と出て失敗する。
- https://bugs.launchpad.net/ubuntu/+source/python-debian/+bug/1926870
 - https://github.com/python-poetry/poetry/issues/4022
 - https://github.com/python-poetry/poetry/issues/6013#issuecomment-1186090946
 - https://github.com/python-poetry/poetry/issues/4231
 
poetry 側の問題ではなくパッケージ側が PEP 440 に準じていないのが問題らしい。2 つ目のリンクのの人が書いてくれているように /usr/lib/python3/dist-packages/ にあるファイルをいじったら動いた。正直このディレクトリが何なのか 1 ミリもわからない。
ただ、 lock file を書いている途中でなんかコケた。もう疲れたし lock file だからいいや...
追記:なんか再起動したらなおった。