Skip to content

How to Prevent Python Package Test Data from Appearing in Windows Search

Problem: Windows Search Suggested “YouPorn” When I Typed “YouTube”

I was demoing my machine to a colleague. I hit the Windows key and typed “YouTube” to open the site.

Windows Search suggested:

YouTube
YouPorn (C:\anaconda3\Lib\site-packages\protego\tests\www.youporn.com)

My colleague saw it. I wanted to die.

The file wasn’t porn. It was a test fixture from the Protego Python library—a robots.txt parsing tool that uses real domain names for testing.

But Windows Search didn’t care. It indexed everything in my user profile, including:

C:\Users\me\AppData\Local\Continuum\anaconda3\pkgs\protego\info\test\tests\test_data\www.youporn.com
C:\Users\me\AppData\Local\Programs\Python\Python311\Lib\site-packages\protego\tests\www.youporn.com
C:\Users\me\.conda\envs\research\Lib\site-packages\protego\tests\www.youporn.com

Every environment I’d ever created was indexed.

I needed to fix this immediately.

Why Windows Search Indexes Python Packages

Windows Search has a simple default behavior:

Index everything in user profile directories.

This includes:

  • Documents, Desktop, Downloads (expected)
  • AppData\Local, AppData\Roaming (where Python packages live)
  • All subdirectories, no matter how deep

Windows Search sees:

  • .com extension → treats as application
  • File name “www.youporn.com” → suggests when typing “YouTube”
  • No awareness that this is test data in a development directory

The indexing flow looks like this:

graph TD
A[User Types in Windows Search] --> B{Indexed Locations?}
B -->|User Profile| C[Search All Files]
B -->|Excluded Path| D[Skip Directory]
C --> E[Match Found: www.youporn.com]
E --> F[Show as Application in Results]
F --> G[User Sees Inappropriate Suggestion]
G --> H[Colleague Sees It Too]

Windows has no built-in exclusions for:

  • Python virtual environments
  • Conda package directories
  • Node_modules
  • Go modules
  • Rust cargo directories

Developers are on their own.

Solution 1: Windows Indexing Options GUI (Individual Fix)

I started with the built-in Windows Indexing Options.

Step 1: Open Indexing Options

  1. Press Windows + R
  2. Type control.exe /name Microsoft.IndexingOptions
  3. Press Enter

Or: Control Panel → Indexing Options

Step 2: Review Indexed Locations

I saw “Indexing: x items (Complete)” with two main locations:

  • Microsoft Outlook (if installed)
  • C:\Users\YourName

Step 3: Click Advanced → Indexed Locations

This shows the full tree of indexed paths.

Step 4: Expand User Profile and Examine

I found:

  • C:\Users\YourName (checked)
    • AppData (checked)
      • Local (checked)
        • Continuum (checked)
          • anaconda3 (checked)
            • pkgs ← This needs to be excluded

Step 5: Exclude Python Package Directories

I unchecked these boxes:

  • C:\Users\YourName\AppData\Local\Continuum\anaconda3\pkgs
  • C:\Users\YourName\AppData\Local\Programs\Python
  • C:\Users\YourName\AppData\Roaming\Python
  • C:\Users\YourName\.conda

Step 6: Rebuild the Index

Clicked “Advanced” → “Rebuild”

This took 15 minutes on my machine. Windows re-scanned everything except the excluded paths.

Result: The “YouPorn” suggestion disappeared from Windows Search.

Solution 2: PowerShell Script for Automated Exclusions

I manage multiple Python environments. Manually unchecking boxes in the GUI wasn’t sustainable.

I needed a script to:

  1. Find all Python package directories
  2. Exclude them from Windows Search
  3. Make it repeatable across machines

Problem: Windows Search doesn’t expose a clean PowerShell API for adding exclusions.

Workaround: Use the Registry.

Windows stores search exclusions in:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Search\Gathering Manager
HKEY_CURRENT_USER\Software\Microsoft\Windows Search\Gathering Manager

But these are binary blobs. Not directly editable via PowerShell.

Better approach: Use the Windows Search PowerShell module from the PowerShell Gallery.

First, install the module:

Terminal window
Install-Module -Name WindowsSearch -Scope CurrentUser

Then, create a script to exclude common Python paths:

Terminal window
# Exclude Python package directories from Windows Search
# Run this in an elevated PowerShell prompt
$ErrorActionPreference = "Stop"
# Common Python package paths to exclude
$excludedPaths = @(
"$env:USERPROFILE\AppData\Local\Continuum\anaconda3",
"$env:USERPROFILE\AppData\Local\anaconda3",
"$env:USERPROFILE\AppData\Local\Programs\Python",
"$env:USERPROFILE\AppData\Roaming\Python",
"$env:USERPROFILE\.conda",
"$env:USERPROFILE\AppData\Local\pip"
)
# Check if paths exist before excluding
$existingPaths = $excludedPaths | Where-Object { Test-Path $_ }
if ($existingPaths.Count -eq 0) {
Write-Host "No Python directories found to exclude."
exit 0
}
Write-Host "Found $($existingPaths.Count) Python directories to exclude:"
foreach ($path in $existingPaths) {
Write-Host " - $path"
}
# Attempt to exclude using Windows Search utilities
# Note: This requires manual confirmation via Indexing Options GUI
Write-Host "`nPlease manually exclude these paths in Indexing Options:"
Write-Host "1. Press Windows+R"
Write-Host "2. Type: control.exe /name Microsoft.IndexingOptions"
Write-Host "3. Click Advanced → Indexed Locations"
Write-Host "4. Uncheck the paths listed above"
# Alternative: Launch Indexing Options for the user
Start-Process "control.exe" -ArgumentList "/name Microsoft.IndexingOptions"

The script launches Indexing Options as a convenience. You still need to manually uncheck the boxes.

Why isn’t this fully automated?

Microsoft doesn’t expose a programmatic API for adding search exclusions. The Indexing Options GUI is the official method.

Solution 3: Enterprise Group Policy (IT Administrators)

If you’re managing developer workstations in an organization, use Group Policy.

Policy Path:

Computer Configuration → Administrative Templates → Windows Search

Relevant Policies:

  1. “Set default exclusion paths for Windows Search”

    • Define paths that Windows Search should never index
    • Deploy to all machines via GPO
    • Users can’t accidentally re-index these paths
  2. “Do not allow locations to be added in Indexing Options”

    • Lock down indexed locations
    • Prevent users from adding problematic paths
    • Useful for controlled environments

Example GPO Configuration:

Policy: Computer Configuration > Administrative Templates > Windows Search
Setting: "Set default exclusion paths for Windows Search"
Enable: Yes
Exclusion Paths:
%USERPROFILE%\AppData\Local\Continuum
%USERPROFILE%\AppData\Local\anaconda3
%USERPROFILE%\AppData\Local\Programs\Python
%USERPROFILE%\AppData\Roaming\Python
%USERPROFILE%\.conda
%USERPROFILE%\AppData\Local\pip
%USERPROFILE%\.virtualenvs
%USERPROFILE%\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.*

Deploy via:

  1. Group Policy Management Console
  2. Link to Developer Workstations OU
  3. Run gpupdate /force on target machines
  4. Restart Windows Search service: Restart-Service WSearch

This prevents the issue organization-wide before it starts.

Solution 4: Alternative Search Tools (Developers)

After dealing with Windows Search’s limitations, I explored alternatives.

Everything (voidtools)

What it is: Ultra-fast file search using NTFS indexing

Advantages:

  • Instant search (indexes file names only, not content)
  • Lightweight (~1MB RAM)
  • Doesn’t index by default—you choose what to index
  • Portable version available
  • Regularly updated

Download: https://www.voidtools.com/

Setup for Python development:

  1. Install Everything
  2. Open Tools → Options → Exclude
  3. Add these paths:
    C:\Users\YourName\AppData\Local\Continuum
    C:\Users\YourName\AppData\Local\anaconda3
    C:\Users\YourName\AppData\Local\Programs\Python
    C:\Users\YourName\AppData\Roaming\Python
    C:\Users\YourName\.conda
  4. Save and restart Everything

Result: Fast search without embarrassing suggestions.

Wox Launcher

What it is: Open-source launcher similar to Alfred (macOS) or Spotlight (Linux)

Advantages:

  • Plugin-based architecture
  • Web search integration
  • File search plugin with exclusions
  • Customizable keyboard shortcuts
  • Active development

Download: https://www.wox.one/

Setup:

  1. Install Wox
  2. Enable File Search plugin
  3. Configure exclusions in plugin settings
  4. Set custom hotkey (default: Alt + Space)

Comparison:

FeatureWindows SearchEverythingWox
SpeedMediumInstantFast
IndexingAutomaticManual/SelectiveManual
ExclusionsAfter-the-factProactiveProactive
Web SearchIntegratedNoYes (plugins)
Enterprise SupportYes (GPO)NoNo
Developer-friendlyNoYesYes

Solution 5: Preventive Environment Setup (Best Practice)

I learned that prevention beats fixing. Here’s how I set up new Windows machines for Python development.

Option 1: Dedicated Development Partition

Create a separate drive or partition for development:

C:\ (Windows and apps)
D:\dev (all development work)

Exclude the entire D:\dev from Windows Search.

Benefits:

  • All code in one location
  • Single exclusion rule
  • Easy to backup
  • Separate from personal files

Option 2: Organized User Directory Structure

Keep virtual environments in predictable locations:

C:\dev\
├── projects\ (individual project repos)
├── venvs\ (global virtual environments)
└── conda\ (all conda environments)

Exclude C:\dev from Windows Search once.

Option 3: Project-Level .venv Directories

Use .venv in project directories (Python 3.3+ standard):

C:\Users\YourName\source\
├── project-a\
│ ├── .venv\
│ └── src\
└── project-b\
├── .venv\
└── src\

Add .venv to Windows Search exclusions:

C:\Users\YourName\source\**\.venv

Windows Search supports wildcards in exclusion paths.

Document this in team onboarding:

# Windows Development Machine Setup
## Python Environment
1. Install Python to `C:\Python311` (not AppData)
2. Create `C:\dev` for all development work
3. Exclude `C:\dev` from Windows Search:
- Windows+R → `control.exe /name Microsoft.IndexingOptions`
- Advanced → Indexed Locations → Exclude C:\dev
## Virtual Environments
Use project-local `.venv` directories.
Already excluded via `C:\dev` wildcard rule.
## Verification
After setup, verify Windows Search doesn't index package directories:
1. Press Windows key
2. Type "protego" (or any installed package)
3. Should show: "No results found"

Package Maintainer Best Practices

If you maintain Python packages, you can prevent this issue for your users.

Problem Test Data

The Protego library includes www.youporn.com as a test fixture. Legitimate choice for testing robots.txt parsing against real-world domains.

But on Windows, this causes embarrassment.

Better Practices

1. Use Example Domains

Instead of real adult domains:

www.example.com
www.example.org
test.example.net

The example.com, example.org, and example.net domains are reserved for documentation and testing (RFC 2606).

2. Obfuscated Domain Names

If you need realistic testing:

www.example-p0rn.com
test.adult-site.example
phishing-target.evil.com

Humans recognize the intent. Windows Search won’t suggest them.

3. Separate Test Data Package

Don’t ship test data with the main package:

protego/ # Main package (no test data)
protego-tests/ # Test data (separate install)

Users only install test data if they need it:

pip install protego
pip install protego-tests # Optional, for developers

4. Document Test Data Content

Add to README:

## Test Data
This package includes real-world domain names for testing robots.txt parsing.
Some test fixtures include adult domain names (e.g., for testing adult site robots.txt).
On Windows, these may appear in Windows Search. Exclude the package directory:

Transparency beats surprise.

My Trial-and-Error Process

Here’s what I tried before finding working solutions.

Attempt 1: Delete the Files

  • Delete www.youporn.com from site-packages
  • Problem: Reappears on every pip install protego --upgrade
  • Verdict: Temporary fix, not sustainable

Attempt 2: Add Hidden Attribute

attrib +H www.youporn.com
  • Problem: Windows Search still indexes hidden files
  • Verdict: Doesn’t work

Attempt 3: Move Files Outside User Profile

  • Changed Anaconda install location to C:\anaconda3
  • Problem: New packages still went to AppData\Local
  • Verdict: Incomplete solution

Attempt 4: Disable Windows Search Entirely

  • Disabled Windows Search service
  • Problem: Broke Start menu search, File Explorer search
  • Verdict: Too extreme, breaks core Windows functionality

Attempt 5: Windows Indexing Options

  • Excluded Python directories via GUI
  • Rebuilt index
  • Problem solved
  • Verdict: Working solution, requires manual setup

Attempt 6: Alternative Search Tools

  • Installed Everything Search
  • Excluded Python directories
  • Problem solved with better search performance
  • Verdict: Best long-term solution for developers

What worked:

  1. Windows Indexing Options exclusions (immediate fix)
  2. Alternative search tools (better developer experience)
  3. Preventive environment setup (prevents future issues)

Why Microsoft Doesn’t Fix This

Windows Search lacks developer-aware defaults because:

  1. Target Audience: General users, not developers
  2. Backwards Compatibility: Can’t change default indexing behavior without breaking existing workflows
  3. Complexity: Detecting “development directories” is non-trivial
  4. Enterprise Control: IT admins manage exclusions via GPO, not default settings

Microsoft expects:

  • Individual users to use Indexing Options GUI
  • Organizations to deploy Group Policy
  • Developers to use third-party tools

This isn’t changing soon.

What I Learned

The “YouPorn in Windows Search” incident taught me:

  1. Windows Search has no developer awareness. It indexes everything in user profiles, including package test data.

  2. Exclusions are manual. No API for programmatic exclusion. GUI or Group Policy only.

  3. Alternative tools exist. Everything and Wox are developer-friendly alternatives.

  4. Prevention beats reaction. Set up dedicated development directories and exclude them proactively.

  5. Package maintainers can help. Use example domains, not real adult sites, in test fixtures.

  6. Document for your team. Add Windows Search setup to onboarding docs.

  7. Test your setup. After excluding directories, verify embarrassing files don’t appear in search results.

Now when I demo my machine, Windows Search shows YouTube, not YouPorn.

Final Words + More Resources

My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments