LoginSignup
22
21

More than 3 years have passed since last update.

VSCodeで自作モジュールimport時のエラー表示(unresolved import 'hoge')が消えない

Posted at

はじめに

VSCodeでの開発時(Python3)、実行ファイルと同階層に配置している自作モジュールのimportエラーがどうしても解消できず、地味~にハマったので対策を共有。結論を先に書くと、単なるオートコンプリートの設定漏れでした。。。

環境設定

  • Windows10(64bit)
  • Visual Studio Code 1.41.1
  • Python 3.7.3(64bit)

発生事象

  • 実行ファイルと同階層に配置した自作クラスをimport時、「unresolved import」エラーが消えない
  • 表示上はエラーが出ているが、プログラムを実行すると問題なく動作する 001.png

対策

ワークスペースの設定(settings.json)に「python.autoComplete.extraPaths」を追加、
自作モジュールがあるフォルダのPathを記述すればOK。今回の例は以下のとおり。

settings.json
{
    "python.autoComplete.extraPaths": ["./src/get_tweet_data"]
}

参考記事

22
21
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
22
21