{"id":23462,"library":"cppimport","title":"cppimport","description":"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.","status":"active","version":"26.4.17","language":"python","source_language":"en","source_url":"https://github.com/tbenthompson/cppimport","tags":["cpp","pybind11","import","compilation","c++"],"install":[{"cmd":"pip install cppimport","lang":"bash","label":"Default install"}],"dependencies":[{"reason":"Required for compiling C++ code into Python modules.","package":"pybind11","optional":false}],"imports":[{"note":"Main module for importing C++ files.","symbol":"cppimport","correct":"import cppimport"}],"quickstart":{"code":"import cppimport\ncppimport.force_reload()\nimport my_cpp_module  # assumes my_cpp_module.cpp exists and is configured\n","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade to >=26.4.17. If you used cppimport internals referencing distutils, update to setuptools._distutils.","message":"Version 26.4.17 removed the use of distutils and the 'dry-run' kwarg, which may break code relying on older internal APIs.","severity":"breaking","affected_versions":"<26.4.17"},{"fix":"Call cppimport.force_reload() before importing the module after modifying the .cpp file.","message":"cppimport does not recompile automatically when the C++ source changes; you must call cppimport.force_reload() or delete the .so file.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure your .cpp file contains PYBIND11_MODULE(your_filename, m) where your_filename matches the .cpp filename.","message":"The C++ file must define a valid PYBIND11_MODULE (or similar) entry point, and the module name in the macro must match the filename.","severity":"gotcha","affected_versions":"all"},{"fix":"Upgrade to get package version via cppimport.__version__.","message":"Older versions (<22.08.02) did not expose version via __version__.","severity":"deprecated","affected_versions":"<22.08.02"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run 'pip install cppimport' in the correct environment.","cause":"cppimport is not installed or the Python environment does not have it.","error":"ModuleNotFoundError: No module named 'cppimport'"},{"fix":"Create the .cpp file with the correct name (e.g., mymodule.cpp for 'import mymodule').","cause":"The C++ source file is missing or the filename does not match the import statement.","error":"RuntimeError: Cannot load cppimport extension: No such file or directory: ..."},{"fix":"Update PYBIND11_MODULE(mymodule, m) to match the filename (mymodule.cpp).","cause":"The PYBIND11_MODULE macro in the C++ file does not match the module name used in Python.","error":"ImportError: dynamic module does not define module export function (PyInit_...)"},{"fix":"Upgrade to the latest version with 'pip install --upgrade cppimport'.","cause":"Using an old version of cppimport that does not have force_reload (added in v22.05.10?).","error":"AttributeError: module 'cppimport' has no attribute 'force_reload'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}