audrey.feldroy.com
The experimental notebooks of Audrey M. Roy Greenfeld. This website and all its notebooks are open-source at github.com/audreyfeldroy/audrey.feldroy.com
# One-Liner to Clean Python Bytecode
by Audrey M. Roy Greenfeld | Thu, Feb 20, 2025
How to remove stale .pyc files and __pycache__ directories, using uvx + pyclean.
Overview
I like to use the PyClean tool by Peter Bittner like this:
uvx pyclean .
This one-liner:
- Creates an ephemeral virtualenv with
uvx
- Installs pyclean from PyPI into it
- Runs it to remove all Python bytecode files from the current dir, recursively
- Auto-deletes the venv, including pyclean
Example
Here I run it on several of my git repos:
(uv) fun % uvx pyclean .
Cleaning directory .
Total 93 files, 34 directories removed.
uvx and the uv Tool Interface
uvx
is an alias for uv tool run
, part of the uv Python package manager.
It creates a single-use disposable virtualenv for whatever tool you install and run with it. Here the tool name matches the PyPI package name, but it does also support uvx <package-name>:<command-name>
.
© 2024-2025 Audrey M. Roy Greenfeld