LoginSignup
1
0

More than 1 year has passed since last update.

VScodeでDjangoのライブラリが「Import XXX could not be resolved from source」になるとき

Posted at

発生したこと

image.png
・URLの設定を記述する「urls.py」でdjangoのライブラリを使おうとするとVScodeがエラーを知らせてきた
・16行目「from django.urls」の部分で(黄色い波線)
Import django.urls" could not be resolved from sourcePylancereportMissingModuleSource
と言われている

問題の内容

・対応するソースファイルがないインポートに対する診断
・django.urlsがないってことらしい

仮説/前提条件

・仮想サーバーは立ち上げられるのでdjango自体が入っていることは間違いない
・djangoのモジュールを探す場所が違う
・importしなきゃいけない何かがある

解決方法

①表示→Command Palette...を選択
image.png
②インタープリンタを選択
image.png
③「Python3.9.13 64-bit」を選択
image.png
④治った
image.png

原因

・VScodeに入れてる「pylance」という拡張機能はpythonインタープリターを使用してコードを分析し、コードの作成中にエラーをマークする
・この時に仮想環境のインタプリンタが設定されていると、djangoのmoduleが認識されなかった

インタプリンタとは

プログラミング言語を、コンピュータが解釈・実行できる形式に変換しながら同時に少しずつ実行していくソフトウェアのこと。前も調べたことあったわこれ。

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