keg415
keg415

Reputation: 21

Unresolved import warnings

I'm just getting started with Visual Studio Code. After opening a folder with Python scripts, those that import scripts in the same folder are marked Import xxx could not be resolved Pylance(reportMissingImports). However, the imports exist and the code runs without errors. Imports of library modules are not marked as errors.

Setting Python > Analysis: Extra Paths to . did not help.

Problems

Upvotes: 1

Views: 722

Answers (3)

keg415
keg415

Reputation: 21

The false Import xxx could not be resolved Pylance(reportMissingImports) problems were occurring with Visual Studio Code and the Python VSCode Extension installed by Chocolatey.

  1. Uninstall both
  2. Delete the .vscode folder
  3. Reinstall the Visual Studio Code
  4. And instead, installing the "Pylance VSCode Extension" fixed this issue.

Upvotes: 0

JialeDu
JialeDu

Reputation: 9883

Please try adding the following configuration in the settings.json file

    "python.analysis.diagnosticSeverityOverrides": {
    "reportMissingImports": "none",
    },


If your script file is in the same folder as the module files you import, it will never fail. So please check your settings (user setting and workspace setting) if there is any setting that is causing the error.

enter image description here

Additional solutions:

Add the following configuration in settings.json:

// Change the path to your own folder path
    "python.analysis.extraPaths": [
        "C:\\Users\\Admin\\Desktop\\euler",
    ]

Upvotes: 0

Greg Cowell
Greg Cowell

Reputation: 693

You need to tell Visual Studio Code the path to python for your project. Your python binary is probably located inside your virtual environment. Click Settings, Workspace and search for Python default interpreter path and paste in the relevant path.

You can determine the path after activating your virtual environment in a terminal using one of the following commands.

Windows command:

where.exe python

Linux command:

type python

Visual Studio Code will save this information in a settings.json file in the .vscode folder.

Upvotes: 2

Related Questions