Autocomplete python in vscode remote container

Viewed 3775

I'm using the vscode extension importmagic which works fine when not working in a remote container. In the remote container I don't see my own classes and functions as suggestions for autocomplete.

I've tried adding

        "python.autoComplete.extraPaths": [
            "${workspaceFolder}",
        ],

to the settings in devcontainer.json where workspaceFolder=/app. If I set it to ${workspaceFolder}/module it gives me suggestions for the underlying modules.

For example I have a structure like module/sub_module/sub_sub_module and it will suggest and add import automatically like from sub_module.sub_sub_module import ... but module is not included in the import so the import can't be resolved.

Is there a setting that I'm missing or why can't it detect underlying module when using only workspaceFolder as extraPaths?

3 Answers

Change the Python-Server in settings.json from "Pylance" or "Microsoft" or whatever you are using- to "Jedi"

"python.languageServer": "Jedi"

To be honest, no solutions worked for me except this one.

One of the solution is keep adding all the paths to extraPaths which doesn't sound good. Instead use "Jedi" server. No need to add any extraPaths, it uses the directory of open files and folders for autocomplete and analysis by default.

You need to make sure that the extensions installed locally in vscode are also installed in the remote container. In your case the Python extension that allows the autocomplete features and many others are not installed.

Try to access to Preferences/Extensions and install them manually.

Make sure VSCode is using the Python Interpreter from the container (instead of your local). You can do that in VSCode by typing cmd + p -> Python: Select Interpreter -> Select the version from the container.

Related