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 cppimportVerified import paths — ran on the pinned version, not inferred.
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.
Upgrade to >=26.4.17. If you used cppimport internals referencing distutils, update to setuptools._distutils.
Call cppimport.force_reload() before importing the module after modifying the .cpp file.
Ensure your .cpp file contains PYBIND11_MODULE(your_filename, m) where your_filename matches the .cpp filename.
Upgrade to get package version via cppimport.__version__.
Run 'pip install cppimport' in the correct environment.
Create the .cpp file with the correct name (e.g., mymodule.cpp for 'import mymodule').
Update PYBIND11_MODULE(mymodule, m) to match the filename (mymodule.cpp).
Upgrade to the latest version with 'pip install --upgrade cppimport'.