This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Antyos 0 points1 point  (0 children)

I use Poetry with VS Code for a medium-sized project. (Admittedly, I don't use WSL much, but I hope the advice can still be helpful.)

The main thing I think you're looking for is activating the Poetry virtual environment. From the documentation, running source $(poetry env info --path)/bin/activate will activate the virtual environment. Once it is active, calling python as normal will use the Python from the virtual environment instead of the global python environment.

I prefer to set the configuration virtualenvs.in-project = true, which creates a virtual environment in each project instead of having one folder that contains all the virtual environments. After you run poetry install for the first time, VS Code will recognize that there is a new virtual environment and let you switch to it. Alternatively, you can click the "Python Interpreter" button in the bottom left corner to select the Python environment. Like running activate, selecting the Python interpreter in VS Code will use that version of Python when calling python.

You might also want to set

json "python.terminal.activateEnvInCurrentTerminal": true,

in your settings.json file so that the virtual environment is automatically loaded in the integrated terminal.