LoginSignup
6
4

More than 3 years have passed since last update.

Formatter autopep8 is not installed. Install? の解決

Posted at

起きてた問題

VScodeでpythonファイルのlint&formattingの設定をしたかった。
python vscode lintなどと検索するとこのような記事に引っかかって、とりあえず書かれるがまま以下のコードをsetting.jsonにそのままコピペしました。

setting.json
"python.linting.enabled": true,
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.lintOnSave": true,
"python.formatting.provider": "autopep8",
"editor.formatOnSave": true

これで何となく保存時に整形を走らせてくれそうだと期待し、保存を試みたところ、VScodeから以下の警告が。
スクリーンショット 2020-06-16 23.52.04.png

Formatter autopep8 is not installed. Install?
というので、そのままYesを押したり、pip install autopep8でグローバルにautopep8をインストールしてみたり、パッケージマネージャとしてPoetryを使っている弊プロジェクトのpyproject.tomlautopep8を書き下したりしても警告は消えず保存時整形はされずで少々難儀していました

解決手順

自分のケースでは以下のコードを追記することで解決しました

setting.json
"python.formatting.autopep8Path": "/Users/USERNAME/.pyenv/shims/autopep8"

formatting.providerとして走ってくれるautopep8のPathを教えてあげる必要があったみたいです。
autopep8のPathは(インストールされていれば)以下の手順で出力できます


$ which autopep8
$ pyenv which autopep8 #pyenvを使っている場合はこっち

参考

https://github.com/microsoft/vscode-python/issues/6495
https://gist.github.com/Tinitto/8d9f9638ff54e0a8351e4ba2d8a37441

6
4
1

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
6
4