[Python] Multiple python interpreters and adding individual files to workspace VSCode

Discussão em 'Python' iniciado por Stack, Setembro 26, 2024.

  1. Stack

    Stack Membro Participativo

    I have a project directory with a structure like this:

    .
    ├── .gitignore
    ├── .vscode
    │ └── settings.json
    ├── README.md
    ├── container1
    │ ├── .vscode
    │ │ └── settings.json
    │ ├── main.py
    │ ├── module1
    │ │ ├── __init__.py
    │ │ └── module1.py
    │ └── venv1
    │ ├── bin
    │ ├── include
    │ ├── lib
    │ └── pyvenv.cfg
    ├── container2
    │ ├── .vscode
    │ │ └── settings.json
    │ ├── main.py
    │ ├── module2
    │ │ ├── __init__.py
    │ │ └── module2.py
    │ └── venv2
    │ ├── bin
    │ ├── include
    │ ├── lib
    │ └── pyvenv.cfg
    ├── docker-compose.yaml
    └── project.code-workspace


    I need the python interpreter to switch between venv1 and venv2 when I navigate between container1 and container2 and I need the interpreter to be aware of the local modules i.e. in container1 it should be aware of module1. The way that I have been able to achieve this so far is by setting up a new VSCode window and then adding the "container1" folder to the workspace, setting the interpreter as venv1 and then doing the same with container2. To be able to see the local modules I've got a .vscode/settings.json file in each container folder with contents like this:

    {
    "python.autoComplete.extraPaths": ["./container1"],
    "python.analysis.extraPaths": ["./container1"],
    }


    The problem is that this approach doesn't allow for me to add the individual files like the README.md or docker-compose.yaml to the workspace. So instead I have to add the whole root directory to the workspace, but to avoid adding the container1 and container2 folders again I have to add the following to the root directory settings.json

    {
    "files.exclude": {
    "container1":true,
    "container2":true
    }
    }



    This whole workflow is really nasty. Is there a better way to achieve all of this?

    Continue reading...

Compartilhe esta Página