VS code venv not detected (WSL)
Asked Answered
S

3

6

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

Swen answered 31/7, 2020 at 7:5 Comment(1)
have you activate the venv?Oospore
M
20

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.

Markswoman answered 19/3, 2021 at 12:32 Comment(0)
L
2

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.

Lowpitched answered 7/3, 2023 at 6:9 Comment(1)
the official Python extension wasnt installed in my WSL environment for me and that fixed the problemAndantino
P
0

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.

Perryperryman answered 31/7, 2020 at 7:7 Comment(4)
[na its the same][1] [1]: i.sstatic.net/JHFck.pngSwen
I've updated my answer. If it doesn't help, please provide more details about your vscode, extensions and wsl setup.Perryperryman
are all the files in my wsl not in my c drive? If not where is it stored?Swen
They are stored in a different way to be compatible with linux environmentPerryperryman

© 2022 - 2024 — McMap. All rights reserved.