profile
viewpoint

Ask questionsPython executable from venv is not used

For some reason the mypy extension doesn't recognize my python executable in a venv.

The log output shows

Mypy extension activated, version 0.2.0
Registering listener for interpreter changed event
Waiting for Python extension to load
Python extension loaded
Listener registered
[1] Check workspace: ${workspaceFolder}
[1] Using config file: mypy.ini
[1] Received python path from Python extension: /usr/bin/python3
[1] Running dmypy in folder ${workspaceFolder}
${workspaceFolder}/env/bin/dmypy --status-file /home/alex/.config/Code/User/workspaceStorage/c75fa14f80a26f7dcd6661af27693d09/matangover.mypy/dmypy-80690f3ce6c54e9de14878ef29f8a83a93369fd9.json run --log-file /home/alex/.config/Code/User/workspaceStorage/c75fa14f80a26f7dcd6661af27693d09/matangover.mypy/dmypy-80690f3ce6c54e9de14878ef29f8a83a93369fd9.log -- . --show-column-numbers --no-error-summary --no-pretty --no-color-output --config-file mypy.ini --python-executable /usr/bin/python3

The --python-executable /usr/bin/python3 is the problem here. It should be ${workspaceFolder}/env/bin/python

The mypy settings are

{
    "mypy.configFile": "mypy.ini",
    "mypy.dmypyExecutable": "${workspaceFolder}/env/bin/dmypy",
    "mypy.targets": ["."]
}

Interestingly, the python extension outputs the following logs, showing that it runs pylance with the system python, but the linters with the venv one:

...
Python interpreter path: /usr/bin/python3
Starting Pylance language server.
> conda --version
Python interpreter path: ${workspaceFolder}/env/bin/python
... (invocations of flake8 and pycodestyle)

Unfortunately, it is not possible in vscode to specify the python path manually (for security reasons). Setting "run using active interpreter" tries to run everything using using the system python which is also not what I want.

matangover/mypy-vscode

Answer questions dimaqq

vscode recently started supporting poetry and perhaps Python interpreter selection was changed or improved? this extension still doesn't find dmypy out of the box though :(

And then it works somehow, magically, after a while. I guess the status is same as reported upstream then... Or maybe it doesn't at all, I can't tell 😞

useful!
source:https://uonfu.com/
Github User Rank List