Ankush
Ankush

Reputation: 79

VS code venv not detected (WSL)

I recently switched over to WSL (Ubuntu). Now when I create a virtual env using

python -m venv venv

It is not detected in vs code automaticaly.

My settings.json

{
    "python.pythonPath": "C:\\Users\\ankus\\AppData\\Local\\Programs\\Python\\Python37-32\\python.exe",
}

I have tried to change it to this

{
    "python.pythonPath": "/mnt/c/Users/ankus/OneDrive/Documents/Main Projects/project_folder/venv/bin/python"
}

but nothing seems to work.

Also, I can see only 1 python interpreter

Upvotes: 7

Views: 15727

Answers (3)

Martin Alexandersson
Martin Alexandersson

Reputation: 1427

It seems that you need to install and enable the Python Extension Pack for your WSL, even though you already have it in your Windows setup.

If i did that, I could add venv:s.

Upvotes: 3

AndyMcGN
AndyMcGN

Reputation: 455

I was having this problem because I wasn't opening the folder through the WSL- Remote extension on VSC.

Try downloading the VSC extension 'Remote - WSL' by Microsoft. Then go to the folder containing your virtual environment and use 'Ctrl + Shift + P' and search for 'Remote WSL: Reopen folder in WSL'

When I did this and opened one of the python files, the venv was found automatically by VSC. You might still need to select an interpreter, but the virtual env should be available this time. I didn't need to change any python.Path settings to make this happen.

Upvotes: 20

UjinT34
UjinT34

Reputation: 4987

Try to set python.venvFolders:

"python.venvFolders": [
    "/mnt/c/Users/ankus/OneDrive/Documents/Main Projects/project_folder/venv"
],

If you use "Remote - WSL" then venv should be created inside WSL. It still might not work under /mnt/c/ or any other windows volume. Try moving your project to some folder inside /home and create venv there.

You can type \\wsl$ in windows explorer to get access to your WSL files.

Upvotes: 0

Related Questions