What is the PTH file format?
A .pth file is a plain-text path configuration file processed by Python's built-in site module at interpreter startup. Each line in the file is either a directory path to append to sys.path, or an import statement to execute as Python code. Blank lines and lines beginning with # are treated as comments and ignored.
.pth files must be placed in a directory that the site module scans - typically site-packages or dist-packages - so Python finds them automatically when the interpreter starts. Package managers such as pip and conda use .pth files to register installed packages on the Python path without modifying the interpreter installation itself.
The format has been stable since Python 1.5.2 (1999) and carries no version information. Files are plain UTF-8 (or ASCII) text, usually just a few lines and under 1 KB.
One important security note: because lines beginning with import are executed as Python code at every startup, a malicious .pth file placed in site-packages achieves persistent code execution - a known injection vector on compromised systems.
Note that .pth is also the extension used by PyTorch for serialized model checkpoints - a binary format entirely unrelated to Python's path configuration. The file's location and contents are the reliable way to distinguish between the two uses.
Security & safety
RISK: MEDIUMA Python .pth file is plain text and cannot run on its own. However, lines starting with 'import' are executed as Python code every time Python starts. A malicious .pth file placed in site-packages is a known persistence/code-injection technique on compromised systems. If you find an unexpected .pth file in your Python site-packages, inspect its contents before trusting it. On a healthy system, all .pth files should correspond to legitimately installed packages.
Format details
in a nutshell- PyTorch Model Checkpoint - PyTorch conventionally saves model state dicts as .pth files (binary Pickle/ZIP format); this conflicts with Python's own .pth path files and .pt is now preferred.
- VisualGPSXP Path File - VisualGPSXP (legacy GPS utility for Windows) saved GPS track paths as .pth; the software is obsolete and this use is extremely rare.
Programs that open PTH files
Technical details
deep spec| Encoding | Plain text, UTF-8 or ASCII |
| Container | Plain text (no wrapper or binary structure) |
| Line syntax | One entry per line: a directory path, an 'import <module>' statement, a blank line, or a '#' comment |
| Processing trigger | Python's 'site' module reads all .pth files in site-packages / dist-packages at every interpreter startup |
| Effect on sys.path | Each valid directory line is appended to sys.path, making its packages importable without explicit path manipulation |
| import-line execution | Lines beginning with 'import' are executed as Python code at startup - a persistence/injection risk on compromised systems |
| Typical file size | Under 1 KB (usually 1-10 lines) |
| File signature | None - plain text with no magic bytes or binary header |
| MIME type | text/plain |
| Required file location | Must reside in a site module-scanned directory: site-packages, dist-packages, or the Python installation root |
| Format stability | Unchanged since Python 1.5.2 (April 1999); no version field; fully backward-compatible |
| Associated OS | Windows, macOS, Linux - wherever Python runs |
| Name collision | .pth is also used by PyTorch for binary model checkpoint files - an entirely different format distinguished by file content and location |
| Released | Python 1.5.2 (1999) - site module formalised .pth processing |
| Latest version | No versioning - format unchanged; behaviour documented in Python 3 'site' module |
| Open standard | Yes · royalty-free |
| Specification | docs.python.org |
PTH conversions
Community Q&A
asked by usersNo questions yet - be the first to ask about PTH files.