visual-studio-codevenv

Can 2 VS Code windows for 2 git clones each work with their own venv?


Background (adjacent to my question)

This doesn't happen often, but sometimes, I get carried away with a proof of concept effort and end up too far down a rapid prototyping rabbit hole, with a bunch of work I want to keep, so I break up and organize my work into a stacked series of small branches using a git squash merge, cherry-pick, followed by a repeating series of git adds, commits, pushes, and branching. As I create an organized commit history to pick related changes for a coherent commit history, I write tests and do linting, which sometimes requires some code changes along the way, so the further I get out of the disorganized mess, the more the new series of stacked branches diverge. Since this creates conflicts, I figured out a way to keep these divergent commit histories flowing smoothly...

I have 1 repo clone containing the messy rapid prototyping code where I organize related changes into separate branches, which I push to github.

I then have a second clone where I pull those branches to lint, test, tweak, then rebase off the previously linted, tested, and tweaked code from the previous branch.

Question

I know some of you are probably shaking your heads right now, but it flows surprisingly smoothly this way. The only problem is that I use 2 VSCode windows and the one for the secondary clone where I do the clean-up cannot resolve the imports. It's really just a minor annoyance, but I tried to figure it out today by setting up the secondary clone with its own venv, but it didn't work, so this is what I see (secondary window above and primary window below):

enter image description here

I imagine this is due to the fact that when I launch VSCode for the primary clone, it uses its venv... for both windows. But the 2 clones are in different directories, so it cannot "find" the imports?


Solution

  • OK. It was pretty simple. I just had to:

    1. On the command line: activate my venv: source .venv/bin/activate
    2. code .
    3. command-shift-p
    4. Click "Python: select interpreter"
    5. Click "Enter Interpreter path"
    6. Paste and hit Enter

    I was mistakenly guessing that just activating the environment (either in the terminal from which I launch vscode or in vscode's terminal) was enough. I probably did this for the primary clone long ago and just forgot.