.PTH

PTH File

Python Path Configuration File
Ask a question
QUICK ANSWER

A .pth file is most commonly a Python path configuration file - a tiny plain-text file that tells Python which extra directories to add to its module search path when it starts. You do not open or run it manually; Python reads it automatically from the site-packages folder. To inspect one, open it in any text editor.

Developer: Python Software Foundation Category: Settings Files Open standard MIME: text/plain
OPENS ON Windows macOS Linux
Related: .ICA · .DS_STORE · .WMZ · .CFG

On this page

19k+ extensions indexed
Last reviewed Sep 11, 2026

Not sure what your file is?

Drop any file into our identifier - we read just the first bytes to name the format.

Identify a file

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: MEDIUM

A 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
FULL NAMEPython Path Configuration Fileaka Python site-packages path file, Python path file
DEVELOPERPython Software Foundationsince Python 1.5.2 (1999) - site module formalised .pth processing
MIME TYPEtext/plain
TYPEplain-text path configuration file
STANDARDOpen · royalty-free
This extension is also used by…
  • 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

Windows3 apps
Notepad Built-in Right-click the .pth file > Open with > Notepad to view the list of paths or import statements.
VS Code Free Open the .pth file in VS Code for syntax-highlighted plain-text viewing and editing.
Python (site module - automatic) Open-source Python processes .pth files automatically at startup from site-packages; no manual open needed.
macOS1 app
TextEdit Built-in Open with TextEdit (plain-text mode) to view the contents.
Linux1 app
Any text editor (nano, vim, gedit) Open-source Open in any text editor; the file is plain ASCII/UTF-8.

Technical details

deep spec
EncodingPlain text, UTF-8 or ASCII
ContainerPlain text (no wrapper or binary structure)
Line syntaxOne entry per line: a directory path, an 'import <module>' statement, a blank line, or a '#' comment
Processing triggerPython's 'site' module reads all .pth files in site-packages / dist-packages at every interpreter startup
Effect on sys.pathEach valid directory line is appended to sys.path, making its packages importable without explicit path manipulation
import-line executionLines beginning with 'import' are executed as Python code at startup - a persistence/injection risk on compromised systems
Typical file sizeUnder 1 KB (usually 1-10 lines)
File signatureNone - plain text with no magic bytes or binary header
MIME typetext/plain
Required file locationMust reside in a site module-scanned directory: site-packages, dist-packages, or the Python installation root
Format stabilityUnchanged since Python 1.5.2 (April 1999); no version field; fully backward-compatible
Associated OSWindows, 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
ReleasedPython 1.5.2 (1999) - site module formalised .pth processing
Latest versionNo versioning - format unchanged; behaviour documented in Python 3 'site' module
Open standardYes · royalty-free
Specificationdocs.python.org

PTH conversions

Community Q&A

asked by users
Ask a quick question
Get help from people who work with PTH files. Be specific - include your system and software version.
No account needed · answers usually within a day

No questions yet - be the first to ask about PTH files.

Frequently asked questions

What is a .pth file in Python?
A plain-text file that adds directories to Python's module search path (sys.path). Place it in site-packages and Python reads it automatically at startup.
How do I open a .pth file?
Open it in any text editor (Notepad, VS Code, nano). It is plain text listing directory paths or import statements.
Is .pth the same as a PyTorch model file?
No - PyTorch also uses .pth for binary model checkpoint files, which is a completely different format (Pickle/ZIP). Python's .pth is plain text for path configuration. PyTorch now recommends .pt to avoid confusion.
Can a .pth file be dangerous?
Lines starting with 'import' in a .pth file are executed as Python code every time Python starts. A malicious .pth in site-packages can persist code execution. Always inspect unexpected .pth files.
How do I add a path using a .pth file?
Create a file like 'myproject.pth' in Python's site-packages directory containing the full path to your project directory on one line. Python will add it to sys.path at next startup.

References

1Python docs - site module (path configuration files)docs.python.org
2DFIR.ch - Python .pth files as a persistence mechanismdfir.ch

Keep exploring

across the database

Top extensions this week

1.AQQAQQ Instant Messenger File
2.CRDOWNLOADChrome Partial Download File
3.PARTPartial Download File
4.DATProgram Data File (generic)
5.EXEWindows Executable (Portable Executable)
6.NOMEDIAAndroid No-Media Marker File
7.TMPTemporary File
8.RPMSGRestricted Permission Message
9.XDWDocuWorks Document
10.BINCD/DVD Disc Image (BIN/CUE)

Related extensions

.ICACitrix Independent Computing Architecture file
.DS_STOREmacOS Finder Desktop Services Store (.DS_Store)
.WMZWindows Media Player Skin
.CFGConfiguration File
.LICLicense File
.CONFConfiguration File

Free file tools

An in-browser file identifier and image converter - everything runs on your device.

Open the toolbox

Browse file extensions A-Z