Visual Studio Code not letting me choose Virtual environment Python

This is a bug I cannot wrap my head around. I should first mention that everything works perfectly on PyCharm notebook Professional Edition (but I prefer VSCode's way of using notebooks).

When I click on Select Kernel, I only see my two base Python environments. Both work. I would however like to use one of my virtual environment. So I used the >Python: Select Interpreter option: enter image description here

Here, it's easy for me to find the path/to/python.exe of my virtual environment (Python 3.12.5) by clicking on Enter interpreter path: enter image description here

However, when I click and locate path/to/python.exe, nothing happens. enter image description here

There is still the Select Kernel button saying that I have not selected any Python environment for my notebook.

Things I did:

Upvotes: 0

Views: 92

Answers (2)

Yash Sanghvi
Yash Sanghvi

Reputation: 74

Option 1: Manually Link the Interpreter

  • Open the command palette (Ctrl+Shift+P) and run:
    Python: Select Interpreter
    
  • Navigate to your virtual environment’s python.exe (e.g., path\to\venv\Scripts\python.exe).
  • After selecting, reload the notebook and check the kernel list again.

Option 2: Edit settings.json

  • Add the kernel path explicitly:
    {
        "jupyter.kernels.trusted": [
            "projectname"  // Name used in `--name` during registration
        ]
    }
    

Option 3: Recreate the Virtual Environment

  • Delete the existing virtual environment and create a new one:
    python -m venv new_venv
    
  • Repeat steps 1–3 with the new environment.

Other Checks:

  • Ensure no path conflicts (e.g., spaces or special characters in the venv path).
  • If using Windows, confirm no antivirus/firewall is blocking VS Code from accessing the venv.

Upvotes: -1

Minxin Yu - MSFT
Minxin Yu - MSFT

Reputation: 4259

  1. Enter interpreter path: path/to/python.exe Then >Jupyter: create interactive Window so that kernel will connect to the Python environment automatically. And now you can select the kernel in your ipynb.

Or

  1. Add virtual environment to the workspace so that python can detect the python.exe.

Upvotes: 0

Related Questions