LoginSignup
17
5

More than 1 year has passed since last update.

VSCodeで Import "***" could not be resolved Pylance(reportMissingImports) が出るときの対処法

Last updated at Posted at 2022-01-20

いろんな環境で同じエラーを吐いていたので、備忘録として残す。How to solve Pylance 'missing imports' in vscode を参考にした。

私の場合、venv で sandbox という仮想環境を作成し、そこにインストールした airflow をインポートする際に標題のエラーが発生していた。インストール先にパスが通っていないことが問題らしいので、追加してやればよい。

まず該当するライブラリの場所を確認する。

$ find -name "airflow"
./sandbox/lib/python3.8/site-packages/airflow
...

パスの場所がわかったら、.vscode/settings.json に以下のように追記する。上記では相対パスで表記されているが、.vscode/settings.json では絶対パスで記述するのがよさそう。

.vscode/settings.json
{
    (その他設定),
    "python.analysis.extraPaths" : [
        "/home/sandbox/lib/python3.8/site-packages/"
    ],
}

最後に、VSCode を再起動すればエラーが発生しなくなる。

17
5
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
17
5