When working on Python projects, you might notice a folder called __pycache__
appearing in your project directories. While this folder is necessary for Python to run efficiently, it can clutter your workspace. In this guide, we'll learn how to hide the __pycache__
folder in Visual Studio Code (VSCode) so you can focus on your work without distractions.
What Is pycache?
The __pycache__
folder is automatically created by Python when you run your scripts. It contains compiled versions of your Python files (with a .pyc
extension). These files help Python execute your code faster by skipping the compilation step when the program runs again.
While it’s a useful feature, the folder itself doesn’t need to be visible while you’re coding.
Set pycache Not Visible in VSCode
Modify VSCode Settings
VSCode allows you to hide files and folders through its settings.
-
Open your VSCode settings by clicking on the gear icon in the bottom-left corner and selecting Settings.
-
Use the search bar at the top to type "files.exclude."
-
Under the "Files: Exclude" section, click Edit in settings.json.
-
Add the following line to the
settings.json
file:"files.exclude": { "**/__pycache__": true }
-
Save the file. Now, the
__pycache__
folder will be hidden from your file explorer.
Alternatively, you can add the pattern directly using the GUI:
-
Open settings (File > Preferences > Settings or press
Ctrl + ,
). -
Search for "exclude" in the settings search bar.
-
Under Files: Exclude, click on the Add Pattern button.
-
Add the pattern
**/__pycache__
and confirm.
Use a .gitignore File
If you’re using Git for version control, you can also add __pycache__
to your .gitignore
file. This ensures the folder is ignored by Git and not pushed to your repository.
-
Create or open a file named
.gitignore
in the root of your project. -
Add the following line:
__pycache__/
-
Save the file. While this doesn’t hide the folder in VSCode, it prevents it from appearing in your Git repository.
Conclusion
Hiding the __pycache__
folder in VSCode makes your workspace cleaner and easier to navigate. By using the steps outlined above, you can customize your setup to focus only on what matters while keeping your project organized.