0
0

More than 1 year has passed since last update.

import パッケージの解決

Posted at

インストールしたパッケージが VS Code エディターで、importエラーになってしまう。
image.png

Import "hello" could not be resolved Pylance reportMissingImports

Pylanceの設定にパッケージフォルダーを追加する

[ファイル]→[ユーザー設定]→[設定 (Ctrl+,)]を開き
python.analysis.extraPathsにパッケージのフォルダーパスを追加する

{
    "python.analysis.extraPaths": [
        "C:\\Python310\\lib\\site-packages\\"
    ]
}

参考:https://github.com/microsoft/pylance-release/blob/main/README.md#settings-and-customization

パッケージフォルダーを確認する

  1. ターミナルで、Pythonを実行
python
  1. パッケージをインポート
>>> import hello
  1. ファイルを確認
>>> print(hello.__file__)

結果

C:\Python310\lib\site-packages\hello\__init__.py
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