[Python] VSCode: Confusion over Conflicting Python Environments

Discussão em 'Python' iniciado por Stack, Fevereiro 18, 2025.

  1. Stack

    Stack Membro Participativo

    I am running WSL: Ubuntu through VSCode. In the terminal, I have a virtual environment, .venv, activated.

    I am trying to run an Electron app with Flask as its backend via the terminal. Running the Electron app gives the error:

    stderr: from jsonschema import validate
    ModuleNotFoundError: No module named 'jsonschema'


    I ran pip freeze > requirements.txt and found that "jsonschema" was, indeed, there

    [​IMG]

    I suspected that this was some error caused by installing the module wrong and added the following lines to my Flask app and ran it independently:

    import sys

    print("Executing in", sys.executable)
    if "jsonschema" in sys.modules:
    print("JSONSchema is in the modules")
    else:
    print("jsonschema isn't in the modules")


    this prints:

    Executing in [...]/.venv/bin/python3
    JSONSchema is in the modules


    Checking the interpreter, it had the Selected Interpreter as "[...]/.venv/bin/python3.10", so I changed it to python3 and restarted VSCode. I activated the virtual environment once more and ran the Flask app independently, which still pointed to python3, then ran the Electron app, which still gave an error. I checked the Interpreter again and found that while the Selected Interpreter is "[...]/.venv/bin/python3", the Workspace's Interpreter is still "[...]/.venv/bin/python3.10"

    [​IMG]

    [​IMG]

    And when I tried to run pip install jsonschema, I got the following messages:

    [​IMG]

    which say that they're installing into python3.10

    So, is python3.10 the interpreter I should be using? If so, how do I change sys to point to it?

    Continue reading...

Compartilhe esta Página