Home > Software engineering >  VS Code cannot find virtual environment on the interpreter, but can find it on integrated terminal
VS Code cannot find virtual environment on the interpreter, but can find it on integrated terminal

Time:03-11

I have a fully working virtual environment installed on my Linux machine. This venv can be regularly used by the terminal in VS code calling source /mypath/venv/bin/activate.

The problem is that the Python interpreter in VS code cannot access any of the packages in the virtual environment, despite setting up the path on the interpreter as described in most of the guides.

I decided to manually set up the path in the settings.json file inside the .vscode folder as follows:

{   
   "python.pythonPath": "/mypath/venv/bin/python3.8"
}

venv is still not accessible through the interpreter. Any other suggestions?

CodePudding user response:

You actually do not need the settings.json file. I've have had a lot of problems lately too.

You could try to remove the .venv folder and create a new one by

python -m venv .env

It seems that vs code have changed something from .venv to .env. Im not sure why.

After doing python -m venv .env open the terminal in vs code and it will active your .env.

You could (if you froze your pip installations) do a pip install -r requirements.txt and you are all good to go.

CodePudding user response:

The default for the "python.envFile" setting is "${workspaceFolder}/.env" change it to "${workspaceFolder}/.venv" and restart vscode.

  • Related