Hide Python bytecode in VS Code by opening Settings (JSON) and adding "files.exclude": { "**/__pycache__": true }, merging that key into the existing object. This removes the folders from the Explorer and search view; set PYTHONDONTWRITEBYTECODE=1 only when you also want Python to stop creating new bytecode files.
How to Hide the pycache Folder in VSCode for a Cleaner Workspace
Hide __pycache__ in VSCode using files.exclude, prevent generation with PYTHONDONTWRITEBYTECODE, and clean up all Python clutter with one settings template.
// The short answer
In this guide · 6 sections
- 01How to Hide pycache in VSCode Using files.exclude
- 02files.exclude vs search.exclude: What’s the Difference?
- 03User Settings vs Workspace Settings: Where Should This Go?
- 04How to Stop Python from Generating pycache in the First Place
- 05A Solid VSCode Settings Template for Python Projects
- 06Troubleshooting: Why is pycache Still Sticking Around?
Few things are as annoying as watching a clean Python project get swallowed by endless __pycache__ folders. They turn your VSCode file tree into visual noise, and worse, they clutter up global search with a bunch of compiled bytecode you'll never actually open or read. Luckily, you can tuck these away with a couple of quick lines in your settings.json, giving you back a tidy workspace and shaving off wasted search overhead instantly.
Target Folder:
__pycache__Configuration File:
settings.jsonConfig Key:
files.excludeGlob Pattern You Need:
**/__pycache__Nuclear Option (Stop Generation Entirely):
PYTHONDONTWRITEBYTECODE=1
How to Hide pycache in VSCode Using files.exclude
The cleanest way to handle this is to tell VSCode right in its config to pretend these compiled files don't exist. Skipping the GUI menus and jumping straight into JSON is way faster: hit Ctrl+Shift+P (or Cmd+Shift+P on a Mac) to pop open the command palette, type Open Settings (JSON), and select it.
Drop this block right into your existing configuration object. Think of files.exclude as your editor’s personal bouncer for the file tree:
JSON
{
"files.exclude": {
"**/__pycache__": true,
"**/*.pyc": true
}
}The second you save, those folders should vanish from your sidebar. The real trick here is that **/ at the start. That tells VSCode, "look down through every nested subfolder in the project, not just the root directory." If you just drop in __pycache__ without the prefix, it only hides folders sitting on the very top surface - anything nested a module or two deeper will stick around to bug you.
files.exclude vs search.exclude: What’s the Difference?
It’s pretty common to get these two mixed up, but they handle different jobs. If you use search.exclude, VSCode only filters stuff out when you run a project-wide search via Ctrl+Shift+F.
The catch? Those folders will still sit right there in your left sidebar, staring back at you.
files.exclude is almost always what you actually want because it kills two birds with one stone. Once you hide a folder from the explorer using files.exclude, VSCode pulls it out of the search index by default too. Since nobody sits around reading compiled .pyc bytecode, hiding it everywhere keeps your sidebar readable and your search snappy.
User Settings vs Workspace Settings: Where Should This Go?
If you want this taken care of once and for all, toss it into your global User settings. That way, any window or Python project you ever open on your machine inherits the clean view automatically without you having to re-configure things every week.
On the other hand, Workspace settings live inside a specific project’s .vscode/settings.json file. These take priority over your global settings, but there's a big gotcha: defining files.exclude at the workspace level won't merge with your global list - it completely overwrites it. If you have custom exclusions set globally, they'll stop applying in that specific project unless you re-add them.
That said, workspace configs are fantastic for teams. Drop your Python exclusions into .vscode/settings.json and check it into git. That way, anyone cloning the repo gets a clean sidebar out of the box, regardless of what their local machine config looks like.
How to Stop Python from Generating pycache in the First Place
If you'd rather not produce these cache files at all, you can actually tell Python to stop writing .pyc files altogether. It keeps your disk completely tidy and nips the problem right at the source.
For a quick one-off run without creating cache, just pass the -B flag when running your script:
Bash
python -B main.pyIf you want Python to behave this way permanently across the board, set the PYTHONDONTWRITEBYTECODE environment variable. Pick the method that fits your setup:
System-wide (Windows):
Bash
setx PYTHONDONTWRITEBYTECODE 1System-wide (macOS/Linux), drop this into your ~/.bashrc or ~/.zshrc:
Bash
export PYTHONDONTWRITEBYTECODE=1Per-project, just add a line to your local .env file (the VSCode Python extension grabs this automatically if your python.envFile is configured):
Bash
PYTHONDONTWRITEBYTECODE=1This instructs Python's runtime to skip compiling bytecode to disk. It's awesome for keeping clean development sandboxes and scratchpads, though keep in mind it comes with a tiny startup penalty since Python has to parse and recompile your modules on every single run.
A Solid VSCode Settings Template for Python Projects
Let’s be honest: cache folders are only half the battle in a busy Python environment. Between test runners, linters, and packaging tools, project folders gather artifacts like dust. A single, well-rounded exclusion block keeps all that background churn out of your face.
Here is a solid template you can paste straight into your settings.json to silence the usual culprits:
JSON
{
"files.exclude": {
"**/__pycache__": true,
"**/*.pyc": true,
"**/.pytest_cache": true,
"**/.mypy_cache": true,
"**/.tox": true,
"**/*.egg-info": true,
"**/build": true,
"**/dist": true
}
}
This sweep takes care of pytest debris, mypy dumps, and distribution builds in one shot. If you tend to keep your virtual environment inside your project folder, you can also toss "**/.venv": true into the mix. You can also manage conda environments with a similar workspace-focused setup if that fits your stack better.
Troubleshooting: Why is pycache Still Sticking Around?
If you added the snippet above and those stubborn folders are still sitting in your sidebar, it usually comes down to one of these quirks:
You missed the **/ prefix. Writing just __pycache__ only matches a folder sitting at the top-level root. Make sure you use **/__pycache__ so VSCode tracks it across all subdirectories.
There's a trailing slash in your pattern. VSCode is pretty picky with glob matching. A trailing slash like **/__pycache__/ breaks the pattern and fails silently. Strip off the slash at the end.
A workspace config is overriding your user settings. If your project has its own .vscode/settings.json with a files.exclude block, it blows away your global list. Check that file, and either merge your patterns there or remove the local block.
The file hasn't been saved or has a syntax slip-up. VSCode applies JSON updates instantly, but only after a successful save. If you missed a trailing comma or broke a bracket, the file won't parse; check your Problems panel (Ctrl+Shift+M) to verify the syntax is valid.
If the sidebar still feels stuck after that, learning how to reset VS Code extension data and cache can help refresh things when the editor’s internal state gets out of sync.
Quick answers
Frequently asked questions
How do I hide __pycache__ in VSCode?
Open Settings JSON (Ctrl+Shift+P → 'Open Settings (JSON)') and add: "files.exclude": { "**/__pycache__": true }. The **/ prefix is required to hide folders at all nesting levels, not just the root.
How do I stop VSCode from showing __pycache__ for all projects?
Add the exclusion to your user-level settings.json (not workspace settings). Open the global settings file via Ctrl+Shift+P → 'Open User Settings (JSON)' and add the files.exclude rule there. It will apply to every VSCode window you open.
What is the difference between files.exclude and search.exclude in VSCode?
files.exclude hides folders from the Explorer sidebar and also removes them from the search index. search.exclude only prevents files from appearing in Ctrl+Shift+F results but leaves them visible in the sidebar. For __pycache__, use files.exclude.
How do I prevent Python from creating __pycache__ folders entirely?
Set the PYTHONDONTWRITEBYTECODE=1 environment variable. On Windows run 'setx PYTHONDONTWRITEBYTECODE 1' in a terminal; on macOS/Linux add 'export PYTHONDONTWRITEBYTECODE=1' to your ~/.bashrc or ~/.zshrc. You can also add it to your .env file for per-project control.
Why is my files.exclude pattern not working for __pycache__?
The most common causes: missing the **/ prefix (use **/__pycache__, not __pycache__), a trailing slash in the pattern (**/__pycache__/ is invalid), or a workspace .vscode/settings.json overriding your global rules. Check the local workspace settings file first.
How do I hide .pytest_cache and __pycache__ at the same time in VSCode?
Add both patterns to files.exclude: { "**/__pycache__": true, "**/.pytest_cache": true, "**/.mypy_cache": true }. You can combine all Python-generated clutter in a single block.
Does hiding __pycache__ affect Python performance?
Hiding it with files.exclude only removes it from the VSCode interface. The folder still exists on disk and Python still uses it for faster startup. If you want to stop generating it entirely, use the PYTHONDONTWRITEBYTECODE variable, though this slightly increases startup time on repeated runs.
Something wrong or out of date?
Tools change fast. Tell the editor what no longer works.