- Published on
Fixing VS Code Not Detecting a pyenv Virtual Environment in WSL
- Authors

- Name
- hwahyeon
I created a virtual environment with pyenv in WSL running Ubuntu 18.04 LTS, but Visual Studio Code did not detect it. Conda environments appeared correctly, while the environment created with pyenv did not.
The following are the methods I tried to solve the problem.
1. Reinstalling WSL and the Virtual Environment
I first reinstalled WSL and recreated the virtual environment in case the problem had been caused by a mistake during the initial development environment setup.
However, this did not solve the problem.
2. Checking Whether the Virtual Environment Was Activated
I checked whether the virtual environment had been activated correctly in the WSL terminal.
However, activating the environment alone did not make it appear in VS Code.
3. Installing Remote - WSL in VS Code
When VS Code is launched for the first time from WSL using code ., VS Code Server is installed. Depending on the version, the installation may be automatic or manual.
If VS Code Server is not installed, VS Code may not be properly connected to WSL.
In the VS Code Explorer, check whether [WSL: UBUNTU-version] appears next to the project name. If it does not appear, VS Code may not be properly connected to WSL.
In this case, install Remote - WSL from the VS Code Extensions panel.

After installing Remote - WSL, launch VS Code from WSL. The virtual environment should then be detected automatically.