Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RawrBear/f711a16d962608ca6c6ab0edbac93b2d to your computer and use it in GitHub Desktop.
Save RawrBear/f711a16d962608ca6c6ab0edbac93b2d to your computer and use it in GitHub Desktop.
Instructions to setup a VENV and get VSCode/Pylance to use it. This hopefully fixes issues with Pylance complaining about packages not being installed when they actually are.
1. Create 2 dirs: **virtual_envs** and **pyvers**
2. Download the Python version you want to use.
3.Run the python.exe
**IMPORTANT:** UNCHECK "Add Python to PATH"
4. Click "Customize Installation"
5. Click "Next" unless you want to modify the options. I uncheck "Documentation" but it's up to you
6. Click "Browse" to choose your install dir. This will be the **pyvers** dir you created earlier. **NOTE:** Python automatically adds "Python<ver number>" as the dir for the version you're installing. I change this to "py<ver number>" so for eg: "...pyver\py311". If you're installing different minor versions, you can add that to the end of the dir name.
7. Open CMD Prompt and follow this pattern, add your path as needed: **<path to pyver>\<py ver>\python -m venv <path to virtual_envs>\<name of project>**. If you're making a project called "my_awesome_project", you would use that for <name of project>
8. In VSCode, open a CMD Prompt and activate your venv with **<path to venv>\Scripts\activate**
9. Press shift+ctrl+p to open the command pallet
10. In the box, type **"python"** and choose **"Python: Select Interpreter"**
11. In the next box, select **"+ Enter interpreter path..."** and go to **<virtual_envs>\<your_new_env>\Scripts\Python.exe**
That should fix Pylance and make VSCode using the same venv as you;re using in the terminal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment