How to specify correct python version for Python Language Server when using multi-root workspace

1.4k Views Asked by At

Does anyone know how to specify correct Python version when use newest VSCode Python extension(ms-python.python) with multi-root workspace?

My global python environment is 2.7 and my VSCode project's directory structure is like below:

root ├ .vscode │ ├ childA(Python2.7) │ ├ .venv(virtualenv directory created by Pipenv) │ └ .vscode │ └ childB(Python3.7) │ ├ .venv(virtualenv directory created by Pipenv) └ .vscode

I set pythonPath both child directory's .vscode/settings.json file like below: "python.pythonPath": ".venv/bin/python"

Recently I updated VSCode Python extension, after that, under ChildB directory, Python extension always displays error message like below: [Python] invalid syntax, parameter annotations require 3.x [E16]

I use type annotation like below: def add(p1: int, p2: int) return p1 + p2

This error message is returned by Python Language Server that I found here: https://github.com/Microsoft/python-language-server/blob/7be329643299111cc1f0839d20aa9eb146b0d381/src/Analysis/Engine/Impl/Parsing/Parser.cs#L2088

When I doesn't use multi-root workspace, this error is not displayed.

I think newest Python extension can't recognize correct Python version that I set in .vscode/settings.json when I use multi-root workspace.

I want Python Language Server to recognize correct Python version in childB directory.

Any suggestions?

1

There are 1 best solutions below

3
On

Settings for a multi-root workspace are not specified in a vscode/settings.json file but in your .vscode-workspace file.