I'm using a monorepo with multiple packages in separate directories. Poetry is in charge of package management including creating the virtual environment.
I wish VS Code would use the right Python interpreter for each package individually. Is that possible? My workaround is to open a separate window with the directory containing a package, so all of its files would use the right interpreter.
Select Add Folder to Workspace in the menu. As a simple example I have added three folders


Then click on the python interpreter version in the lower right corner (or Ctrl+Shift+P --> Python:Select Interpreter)

Choose a folder, here I choose folder1

Now select interpreter for folder1 folder

The same operation continues to select interpreters for folder2 and folder3.
Of course this is just the basics, you can also create virtual environments for each folder and then choose the interpreter for the virtual environment for each folder.
For example, I created a virtual environment .venv2 under the folder2, the same step 2 and 3, and then I selected the interpreter under the virtual environment .venv2.

There is also a way to specify the default interpreter path in the settings.json, but after setting it also requires step 2 and 3 and then select it in the selection panel.

When you modify the folder settings, the .vscode folder and the settings.json file will be automatically generated under the folder. The contents of the settings.json file are the settings you just modified

And this step is reversible. You can manually create the .vscode folder and add the settings.json file in it. And enter the corresponding settings in the settings.json file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With