Registry / ai-ml / cppimport

cppimport

JSON →
library26.4.17pypypi✓ verified 85d ago

Import C++ files directly from Python by automatically compiling them with pybind11. Version 26.4.17, updated to work with Python up to 3.14, replacing deprecated distutils with setuptools._distutils.

pip install cppimport
INSTALL
IMPORT
SIG · CPPIMPORT
C
cppimport
ai-mlpythonv26.4.17
Install
4.2s avg
Import
30ms
Disk
22MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v26.4.17 · 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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.026s · 20.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 4.2s · import 0.034s · 21MB
22MB installed
● package 22MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

cppimport
import cppimport
Main module for importing C++ files.

After installing, create a C++ file with a .cpp extension and a corresponding .py file with the same name (or use PYBIND11_MODULE macro). Use cppimport.force_reload() to recompile if the C++ source changes.

import cppimport cppimport.force_reload() import my_cpp_module # assumes my_cpp_module.cpp exists and is configured
cppoimport --version
Debug
Known issues
breakingVersion 26.4.17 removed the use of distutils and the 'dry-run' kwarg, which may break code relying on older internal APIs.
fix
Upgrade to >=26.4.17. If you used cppimport internals referencing distutils, update to setuptools._distutils.
affects: <26.4.17
gotchacppimport does not recompile automatically when the C++ source changes; you must call cppimport.force_reload() or delete the .so file.
fix
Call cppimport.force_reload() before importing the module after modifying the .cpp file.
affects: all
gotchaThe C++ file must define a valid PYBIND11_MODULE (or similar) entry point, and the module name in the macro must match the filename.
fix
Ensure your .cpp file contains PYBIND11_MODULE(your_filename, m) where your_filename matches the .cpp filename.
affects: all
deprecatedOlder versions (<22.08.02) did not expose version via __version__.
fix
Upgrade to get package version via cppimport.__version__.
affects: <22.08.02
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'cppimport'
cppimport is not installed or the Python environment does not have it.
fix
Run 'pip install cppimport' in the correct environment.
RuntimeError: Cannot load cppimport extension: No such file or directory: ...
The C++ source file is missing or the filename does not match the import statement.
fix
Create the .cpp file with the correct name (e.g., mymodule.cpp for 'import mymodule').
ImportError: dynamic module does not define module export function (PyInit_...)
The PYBIND11_MODULE macro in the C++ file does not match the module name used in Python.
fix
Update PYBIND11_MODULE(mymodule, m) to match the filename (mymodule.cpp).
AttributeError: module 'cppimport' has no attribute 'force_reload'
Using an old version of cppimport that does not have force_reload (added in v22.05.10?).
fix
Upgrade to the latest version with 'pip install --upgrade cppimport'.
Upgrade
Version history
26.4.17latest on PyPI · released Apr 17, 2026
Audit
Dependencies
pybind11requiredRequired for compiling C++ code into Python modules.
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
cppimport — pip install cppimport · libregistry