VS Code does not show Python because the Python extension is missing or the interpreter is not selected for the workspace. Install the extension and set the correct interpreter to restore syntax highlighting, IntelliSense, and run‑time features.
Missing Python Extension
The most common reason is that the official Python extension from Microsoft is not installed. Without it, VS Code treats .py files as plain text.
- Open the Extensions view with the sidebar icon or the menu View > Extensions.
- Search for "Python" authored by Microsoft.
- Click Install. The extension will download and enable language features.
- Reload the window when prompted.
After installation, open a .py file. You should see coloured keywords, underlines for errors, and a small Python icon in the status bar.
Interpreter Not Selected
Even with the extension, VS Code needs to know which Python interpreter to use. If none is chosen, the editor cannot provide linting, debugging, or code completion.
- Look at the blue status bar at the bottom. If it reads "Select Python Interpreter", click it.
- A list of discovered interpreters appears – for example,
C:\Python39\python.exeor/usr/bin/python3. - Select the version you want to work with. The choice is remembered per workspace.
When the interpreter is set, the status bar shows the full path and the language server activates. You can verify by opening the output panel (View > Output) and selecting "Python" from the dropdown – a short log should confirm the interpreter path.
File Association Issues
Sometimes VS Code treats a Python file as a different language because the file association is overridden.
- Open the Command Palette (Ctrl+Shift+P or Cmd+Shift+P) and run "Change Language Mode".
- Choose "Python" from the list. This sets the language for the current file.
To make the change permanent, add a setting in settings.json:
{
"files.associations": {
"*.py": "python"
}
}
This tells VS Code to always treat *.py files as Python.
Why the Steps Matter
The extension provides the language server, which parses the code, offers IntelliSense, and runs linters. The interpreter tells the server which version of Python syntax to expect – for example, f‑strings are valid in Python 3.6 and later but cause errors in earlier versions. Without a selected interpreter, the server defaults to a generic parser that cannot resolve imports or virtual‑environment packages, so you see no suggestions.
File association determines the grammar used for tokenising the text. If a file is mistakenly opened as "Plain Text", no colourisation occurs, and the extension never activates because it watches only files with the "python" language identifier.
Worked Example: From Blank File to Running Script
Imagine you create a new folder demo and add hello.py with the following content:
def greet(name):
return f"Hello, {name}!"
print(greet("World"))
When you open this file in VS Code, you see only black text. Follow these steps:
- Install the Python extension as described earlier.
- Click the status‑bar prompt and select the interpreter located at
C:\Python311\python.exe. - Observe that keywords
defandreturnturn blue, the string becomes green, and a lightbulb appears suggesting "Add missing import for f‑string" – this is the language server at work. - Open the terminal inside VS Code (Terminal > New Terminal) and run
python hello.py. The outputHello, World!appears, confirming the interpreter matches the script.
Now the file displays correctly and you can use auto‑completion for print or navigate to the definition of greet with F12.
Common Misconception and the Correct Fact
Many users think that simply opening a .py file automatically activates Python support. The correct fact is that VS Code requires the dedicated Python extension and a selected interpreter; without both, the editor treats the file as plain text.
Next Steps After Restoring Python View
Once the language features are visible, you can enhance your workflow further:
- Enable a linter such as
flake8by installing it in your environment (pip install flake8) and adding"python.linting.flake8Enabled": truetosettings.json. - Activate a formatter like
black(pip install black) and set"editor.formatOnSave": trueto keep code style consistent. - Configure a virtual environment for the project (
python -m venv .venv) and select its interpreter to isolate dependencies.
These optional steps rely on the same foundation – the extension and interpreter – and will not work until the basic display issue is resolved.
What to Do If Problems Persist
If you still do not see Python syntax after following the above, try these troubleshooting actions:
- Close all VS Code windows and delete the folder
%APPDATA%\Code\User\globalStorage\ms-python.python(Windows) or the equivalent on macOS/Linux. This forces the extension to rebuild its cache. - Check that the file encoding is UTF‑8. Non‑UTF‑8 files can confuse the language server. Change encoding via File > Save with Encoding > UTF‑8.
- Verify that no other extension is overriding the language mode. Disable extensions one by one to isolate conflicts.
- Open the Developer Tools (Help > Toggle Developer Tools) and look for errors in the console related to the Python extension.
Address any error messages by reinstalling the extension or updating VS Code to the latest stable release.