Home > Mobile >  Import "jsonschema" could not be resolved from sourcePylance
Import "jsonschema" could not be resolved from sourcePylance

Time:01-14

I am attempting to use the jsonschema package to validate uploaded JSON payloads from the user.

I have run pip install jsonschema inside my venv and received a message confirming it's installation.

Running pip freeze confirms this. enter image description here

When I attempt to import the package VS Code underlines the package with a yellow squiggly and says "Import "jsonschema" could not be resolved from sourcePylance"

enter image description here

I am able to access the validate function via autocomplete menus, however when I attempt to run via the VS Code run menu it fails with the following message

"ModuleNotFoundError: No module named 'jsonschema'"

If I run it manually from my terminal it executes the code as expected.

My launch.json is provided

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
    {
        "name": "Python: Current File",
        "type": "python",
        "request": "launch",
        "program": "app.py",
        "console": "integratedTerminal",
        "justMyCode": true
    }
]

}

CodePudding user response:

I think this is caused by you choosing incorrect Python interpreter.

You can use "Ctrl Shift P" and type "Python: Select Interpreter" to choose the interpreter where you installed this package.

enter image description here

  • Related