Reputation: 21
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.
Upvotes: 1
Views: 722
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.
.vscode
folderUpvotes: 0
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.
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
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