Help us understand the problem. What is going on with this article?

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

はじめに

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"]
}

参考記事

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした