Install & Compatibility
Where this runs
tested against v3.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 34.3MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 3.1s · import 0.000s · 35MB
33MB installed
● package 33MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
SourceAnalysis
✓ from pygount import SourceAnalysis
ProjectSummary
✓ from pygount import ProjectSummary
✗ import pygount; pygount.source_analysis(...)
While `pygount.source_analysis` is still available, the object-oriented API (`SourceAnalysis` and `ProjectSummary`) is the recommended approach for programmatic use, though still considered 'work in progress' and subject to change.
This quickstart demonstrates how to use `pygount`'s API to programmatically analyze source code files within a directory and summarize the results. It creates dummy files, analyzes them using `SourceAnalysis` and aggregates the results with `ProjectSummary`, then prints the language-specific counts.
import os
from pathlib import Path
from pygount import SourceAnalysis, ProjectSummary
# Create dummy files for demonstration
dummy_dir = Path('./my_project')
dummy_dir.mkdir(exist_ok=True)
(dummy_dir / 'main.py').write_text(
"""# This is a Python file
import sys
def hello(): # Code line
print('Hello, world!') # Code line
# Another comment
"""
)
(dummy_dir / 'README.md').write_text(
"""# My Project
This is a test project.
"""
)
(dummy_dir / '.hidden_file.txt').write_text("should not be counted")
project_summary = ProjectSummary()
# Analyze files in the dummy project directory
for source_path in dummy_dir.rglob('*'):
if source_path.is_file():
try:
source_analysis = SourceAnalysis.from_file(source_path, 'my_project')
project_summary.add(source_analysis)
except UnicodeDecodeError as e:
print(f"Warning: Could not decode {source_path}: {e}")
print("\n--- Analysis Results ---")
for language_summary in project_summary.language_to_language_summary_map.values():
print(language_summary)
# Clean up dummy files
import shutil
shutil.rmtree(dummy_dir)
pygount --version
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pygount'
The 'pygount' package is not installed in the currently active Python environment.
fixInstall pygount using pip: `pip install pygount`
ImportError: No module named pygments
The 'pygments' package, a fundamental dependency for pygount's code parsing, is not installed or accessible in your Python environment.
fixInstall pygments using pip: `pip install pygments`
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x... in position ...: invalid start byte
Pygount attempted to read a source code file using UTF-8 encoding, but the file contains characters encoded differently, leading to a decoding failure.
fixSpecify the correct encoding for the file using the `--encoding` command-line option (e.g., `pygount --encoding=iso-8859-15 .`). You can also try `automatic;iso-8859-15` or `chardet` (requires `pip install chardet`) for heuristic detection.
Could not find a version that satisfies the requirement pygount (from versions: ) No matching distribution found for pygount.
This usually indicates that the Python version in use is too old for the latest pygount release (e.g., pygount 3.x requires Python 3.10 or newer), or pip cannot find a compatible distribution for your system.
fixUpgrade your Python interpreter to version 3.10 or higher. Alternatively, ensure pip is updated (`python -m pip install --upgrade pip`) and try installing within a clean virtual environment.
Upgrade
Version history
3.2.0latest on PyPI · released Apr 8, 2026
Audit
Dependencies
pygmentsrequiredCore dependency for source code parsing and language detection.
chardetoptionalOptional dependency for automatic character encoding detection when using `--encoding=chardet`.