1
1

More than 1 year has passed since last update.

VS Codeがvirtualenv環境を認識しないときの対処法

Posted at

起きたこと

いつもと違うマシンでPythonを動かしたところ、VS CodeがVirtualenv環境を認識してくれませんでした。
これのせいで、例えば以下のようにエラーが出ます↓
image.png
(実際にエラーを表示しているのは「Pylance」という拡張機能で、「import先が見つからないよ」と事前に伝えてくれています)

環境

windows 10
VS Code 1.72.2

対処方法

VS Codeに、仮想環境の場所を教えてあげます

1. Poetry が動かせる環境にて以下を実行

poetry config virtualenvs.path

2. 1で得られたパスを、そのまま以下の場所に入れ込みます

image.png

3. 最後にもう一つ

VS Codeの右下のここを押すと、利用できる仮想環境が出てきます。その中から、2で設定したものを選びます
image.png

はい、要らないエラーが消えました

image.png

参考

https://qiita.com/psychoroid/items/6646d45d6a019f5cf16f
https://qiita.com/makuramoto1/items/b5aa08d5fc1ce6af0fb4

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