LoginSignup
0
0

More than 1 year has passed since last update.

Import "Pydantic" could not be resolvedPylanceのエラーに悩まされ貴重な休日が終わった…

Last updated at Posted at 2023-02-11

WSL2 + VSCode + DevContainer環境で Python + FastAPIの勉強を始めました。

Udemyの動画授業を見ながら、講師に言われるがままソースを少し書いては動かす。
少し修正しては動かすの繰り返し。

from fastapi import FastAPI
from typing import Optional
で動くソースの間は問題なかったのに、

from Pydantic import BaseModel
を書いた瞬間から急にエラー。

インストールされているのになぜ?パスが通っていない?
DevContainer(コンテナ)だから? VSCodeだから?
と、あれこれ悩むこと1日。

× from Pydantic import BaseModel
○ from pydantic import BaseModel

解決してみれば原因は超しょうもないことなのですが、
ふだんWindows環境で開発していて大文字小文字に無頓着だったせいではまってしまいました…。

参考:VSCodeのPylanceの設定について。

With the default configurations, you will get support for autocompletion, but Pylance might not check for type errors.
You can enable type error checks from Pylance with these steps:

Open the "User Settings"
Search for Type Checking Mode
You will find an option under Python › Analysis: Type Checking Mode
Set it to basic or strict (by default it's off)

デフォルトの設定だと型エラーのチェックはしてくれない。
下記の設定を変更するとチェックしてくれるようになる。
VSCodeの設定 "Checking Mode"で検索。
Python › Analysis: Type Checking Mode 
basic か strict に変更する。(デフォルトはoff)

0
0
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
0
0