Search code examples
pythonvisual-studio-codedocoptpylance

Visual studio code reports docopt import error while there are no problems in bash terminal


Just installed extension ms-python.python Visual studio code reports in regard of my code in main.py

Import "docopt" could not be resolved from source 
{
"resource": "/home/XXXXXXXXX/main.py",
"owner": "_generated_diagnostic_collection_name_#0",
"code": {
    "value": "reportMissingModuleSource",
    
"severity": 4,
"message": "Import \"docopt\" could not be resolved from source",
"source": "Pylance",

}

Why i can import module normally and vscode extension ms-python.python can't?

if i run python

 Python 3.9.6 (default, Jul 30 2021, 16:35:19) 
 [GCC 7.5.0] :: Anaconda, Inc. on linux
 Type "help", "copyright", "credits" or "license" for more
 information.
 >>> import importlib
 >>> docopt_spec = importlib.find_loader("docopt")
 >>> found = docopt_spec is not None
 >>> found
 True

Solution

  • In the bash terminal, you are using the Anaconda. Make sure you have select it as the python interpreter or install the docopt package into the environment which you are using.

    The Status Bar always shows the current interpreter.

    enter image description here

    official docs