Collecting cppimport==18.1.10 1 location(s) to search for versions of cppimport: * https://pypi.python.org/simple/cppimport/ Getting page https://pypi.python.org/simple/cppimport/ Analyzing links from page https://pypi.python.org/simple/cppimport/ Found link https://pypi.python.org/packages/06/9b/163c84febd3afcda913cfb686c2c71bcc3c2f8bb68c38e9b01896f32e49e/cppimport-17.7.24.tar.gz#md5=fc428b48a7a2ab71b5f906653ceccf85 (from https://pypi.python.org/simple/cppimport/), version: 17.7.24 Found link https://pypi.python.org/packages/07/26/0af1190fb9f20860ddd0a58115f32f2e850d275a898ccb84688cca1b28c1/cppimport-0.0.9.tar.gz#md5=370f3b6289d420ed6251f8f0a191d0a9 (from https://pypi.python.org/simple/cppimport/), version: 0.0.9 Found link https://pypi.python.org/packages/0e/19/40158dacda04bf90faa3e36e0f3221b7a366d00ff8a368f7b5f7634e58e4/cppimport-0.0.8.tar.gz#md5=251044f150c11b6cc656e4c4f04d6a68 (from https://pypi.python.org/simple/cppimport/), version: 0.0.8 Found link https://pypi.python.org/packages/21/c8/b6544d842a321342dba6d7b5cddb0ad1cf28c104bb5e20e37edf5e506d69/cppimport-0.0.6.tar.gz#md5=a4776edb93fc78260e88fdbcc19f87be (from https://pypi.python.org/simple/cppimport/), version: 0.0.6 Found link https://pypi.python.org/packages/22/c4/c9783cec59f2bc49f9e993dcaf5bfacafb9bc79b61ea3f34689b11c2abf6/cppimport-0.0.3.tar.gz#md5=9461b6bc85e811460b585bd5140f095e (from https://pypi.python.org/simple/cppimport/), version: 0.0.3 Found link https://pypi.python.org/packages/2b/25/be72f3389e378405312d143d96e387bed885601b8e3ae03cf424f311ae57/cppimport-0.0.2.tar.gz#md5=ea558c1d8568e2ff75a1dff40b57e8cc (from https://pypi.python.org/simple/cppimport/), version: 0.0.2 Found link https://pypi.python.org/packages/4b/74/ce33c2673e8ac4e8b73988f73b196c5710d82fcb13c52b7828b0b289f69a/cppimport-17.10.25.tar.gz#md5=c8c51393ec7210d6065a1b21fd17c920 (from https://pypi.python.org/simple/cppimport/), version: 17.10.25 Found link https://pypi.python.org/packages/4d/cf/690066fd4bcf36599497e2a0b22fcfefa35b0bd1c8924b74a42f3f41e12e/cppimport-18.1.10.tar.gz#md5=210b6c60c8d7fac3504af59685316ad9 (from https://pypi.python.org/simple/cppimport/), version: 18.1.10 Found link https://pypi.python.org/packages/5b/c4/590efc9c13f0e1dd2fe7a2dda3e53bc51627692b893badbf4db89284bef3/cppimport-0.0.11.tar.gz#md5=2987f1dcb5f8e407e62aff694dc39060 (from https://pypi.python.org/simple/cppimport/), version: 0.0.11 Found link https://pypi.python.org/packages/65/cd/06560f201954ae5b0e927940aca45f31632a28cde68fd063b0379392dc18/cppimport-18.1.8.tar.gz#md5=304703deb58074f65bf0aa4ab51893f0 (from https://pypi.python.org/simple/cppimport/), version: 18.1.8 Found link https://pypi.python.org/packages/69/0d/2cbff5e4b29b2e4ab8bbda7d8b60090fc47e24fd829fc880b7a924f6647b/cppimport-0.0.4.tar.gz#md5=fe543656985979cd96c457733a0ef69e (from https://pypi.python.org/simple/cppimport/), version: 0.0.4 Found link https://pypi.python.org/packages/81/dc/0b6b1313b26539b8ae3f60b31ce702b7241933d6c69c54831c13df012b4d/cppimport-17.9.18.tar.gz#md5=f6506d7a275a8a65b09eeef4339b2893 (from https://pypi.python.org/simple/cppimport/), version: 17.9.18 Found link https://pypi.python.org/packages/85/7b/3d15a1ffb9d4379c930dc5589276d16e2303f6d2a13131843bbac34f888a/cppimport-0.0.7.tar.gz#md5=9620dc17930f37c14ac6eb85dfaf5175 (from https://pypi.python.org/simple/cppimport/), version: 0.0.7 Found link https://pypi.python.org/packages/92/91/8bd043e2701d36f1e90dc8bc0e584a668410b9d27059b768a4aea480dc1e/cppimport-16.6.23.tar.gz#md5=723cc4b0d075844fbfc3d88df7756a61 (from https://pypi.python.org/simple/cppimport/), version: 16.6.23 Found link https://pypi.python.org/packages/c2/5a/43af90650c4a9aa24c81f81fe41326aa783a57d58b33b7bc289b27319901/cppimport-0.0.10.tar.gz#md5=ed6868db568002df5e678b1fe5d12dc7 (from https://pypi.python.org/simple/cppimport/), version: 0.0.10 Found link https://pypi.python.org/packages/cb/59/72e8fbf2b01cb32aa167cf2841d7d36e1e6e61a2a58567a61e62a7923a18/cppimport-0.0.5.tar.gz#md5=ed55d64f91d59f644512637da70e2de5 (from https://pypi.python.org/simple/cppimport/), version: 0.0.5 Found link https://pypi.python.org/packages/ed/0b/fd89afd8358d7050ec1b9a881a21663dc1dd8906b5d47424ddad33381de2/cppimport-16.6.24.tar.gz#md5=e7b6655ccb019c48c5676a5780355195 (from https://pypi.python.org/simple/cppimport/), version: 16.6.24 Found link https://pypi.python.org/packages/ee/dc/b675eb22eb9d49226657c589bb3b87849488073883b49713a929003deda5/cppimport-18.1.9.tar.gz#md5=be0968be91d95d2dd2b070b33d919f86 (from https://pypi.python.org/simple/cppimport/), version: 18.1.9 Found link https://pypi.python.org/packages/fa/31/bceae3da0503e444fa673fa22016844eb86d750b0caeb6dfa45d4b21845f/cppimport-16.6.tar.gz#md5=1574ac40742ab4623e0d5e8058041044 (from https://pypi.python.org/simple/cppimport/), version: 16.6 Using version 18.1.10 (newest of versions: 18.1.10) Downloading cppimport-18.1.10.tar.gz (4.2MB) Downloading from URL https://pypi.python.org/packages/4d/cf/690066fd4bcf36599497e2a0b22fcfefa35b0bd1c8924b74a42f3f41e12e/cppimport-18.1.10.tar.gz#md5=210b6c60c8d7fac3504af59685316ad9 (from https://pypi.python.org/simple/cppimport/) Running setup.py (path:/tmp/pip-build-cfplh53p/cppimport/setup.py) egg_info for package cppimport Running command python setup.py egg_info ##### If you've used cppimport version 0.0.*, some new features for you! Compiler arguments, multiple source files, bug fixes! Read on. # Import C or C++ files directly from Python! Let's try it out. First, if you're on Linux or OS X, install with the terminal command `pip install cppimport`. Most cppimport users combine it with [pybind11](https://github.com/pybind/pybind11), but you can use a range of methods to create your Python extensions. Raw C extensions, Boost.Python, SWIG all work. Let's look at a simple C++ extension: ```c++ /*cppimport <% setup_pybind11(cfg) %> */ #include namespace py = pybind11; int square(int x) { return x * x; } PYBIND11_PLUGIN(somecode) { pybind11::module m("somecode", "auto-compiled c++ extension"); m.def("square", &square); return m.ptr(); } ``` Save this code as `somecode.cpp`. Open a python interpreter and run these lines [\[1\]](#notes): ```python >>> import cppimport >>> somecode = cppimport.imp("somecode") #This will pause for a moment to compile the module >>> somecode.square(9) 81 ``` I'm a big fan of the workflow that this enables, where you can edit both C++ files and Python and recompilation happens transparently. # I want things to be even easier! (Python import hook) Modify the first section of the .cpp file and add "cppimport" on the first line of the file. This MUST be on the first line. This is explained further down. ```c++ /*cppimport <% setup_pybind11(cfg) %> */ ``` Then import the file using the import hook: ```python >>> import cppimport.import_hook >>> import somecode #This will pause for a moment to compile the module >>> somecode.square(9) 81 ``` # What's actually going on? **The technical description:** cppimport looks for a C or C++ source file that matches the requested module. If such a file exists, the file is first run through the Mako templating system. The compilation options produced by the Mako pass are then use to compile the file as a Python extension. The extension (shared library) that is produced is placed in the same folder as the C++ source file. Then, the extension is loaded. **Simpler language please:** Sometimes Python just isn't fast enough. Or you have existing code in a C++ library. So, you write a Python *extension module*, a library of compiled code. I recommend [pybind11](https://github.com/pybind/pybind11) for C++ to Python bindings or [cffi](https://cffi.readthedocs.io/en/latest/) for C to Python bindings. I've done this a lot over the years. But, I discovered that my productivity goes through the floor when my development process goes from *Edit -> Test* in just Python to *Edit -> Compile -> Test* in Python plus C++. So, `cppimport` combines the process of compiling and importing an extension in Python so that you can type `modulename = cppimport.imp("modulename")` and not have to worry about multiple steps. Internally, `cppimport` looks for a file `modulename.cpp`. If one is found, it's run through the Mako templating system to gather compiler options, then it's compiled and loaded as an extension module. Note that because of the Mako pre-processing, the comments around the configuration block may be omitted. ### Recompilation only happens when necessary: Compilation should only happen the first time the module is imported. The C++ source is compared with a checksum on each import to determine if the file has changed. Additional dependencies (header files!) can be tracked by adding to the Mako header: ``` cfg['dependencies'] = ['file1.h', 'file2.h'] ``` ### I need to set the compiler or linker args! ``` cfg['linker_args'] = ['...'] cfg['compiler_args'] = ['...'] cfg['libraries'] = ['...'] cfg['include_dirs'] = ['...'] ``` For example, to use C++11, add: ``` <% cfg['compiler_args'] = ['-std=c++11'] %> ``` ### I want multiple source files for one extension! ``` cfg['sources'] = ['...'] ``` ### I need more output! Calling `cppimport.set_quiet(False)` will result in output that will be helpful in debugging compile errors. ### Sometimes I need to force a rebuild even when the checksum matches Call `cppimport.force_rebuild()` before running `cppimport.imp(...)`. ### I want incremental compiles on extensions with multiple sources. (For the uninitiated, incremental compilation involves only recompiling those source files that have changed or include headers that have changed.) cppimport is built on top of the setuptools and distutils, the standard library for python packaging and distribution. Unfortunately, setuptools does not support incremental compilation. I recommend following the suggestions on [this SO answer](http://stackoverflow.com/questions/11013851/speeding-up-build-process-with-distutils). That is: 1. Use ccache to (massively) reduce the cost of rebuilds 2. Enable parallel compilation. This can be done with `cfg['parallel'] = True` in the C++ file's configuration header. ### I need information about filepaths in my module configuration code! The module name is available as the `fullname` variable and the C++ module file is available as `filepath`. For example, ``` <% module_dir = os.path.dirname(filepath) %> ``` ### Why does the import hook need "cppimport" on the first line of the .cpp file? Modifying the Python import system is a global modification and thus affects all imports from any other package. As a result, to avoid accidentally breaking another package, the import hook uses an "opt in" system where C and C++ files can specify they are meant to be used with cppimport by having a comment including the phrase "cppimport" on the first line of the file. ### Windows? I don't know if `cppimport` works on Windows. If you're on Windows, try it out and I'll happily accept a pull request for any issues that you fix. I have reports that `cppimport` works on Windows with Python 3.6 and Visual C++ 2015 Build Tools. # cppimport uses the MIT License running egg_info creating pip-egg-info/cppimport.egg-info writing pip-egg-info/cppimport.egg-info/PKG-INFO writing requirements to pip-egg-info/cppimport.egg-info/requires.txt writing dependency_links to pip-egg-info/cppimport.egg-info/dependency_links.txt writing top-level names to pip-egg-info/cppimport.egg-info/top_level.txt writing entry points to pip-egg-info/cppimport.egg-info/entry_points.txt writing manifest file 'pip-egg-info/cppimport.egg-info/SOURCES.txt' reading manifest file 'pip-egg-info/cppimport.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' writing manifest file 'pip-egg-info/cppimport.egg-info/SOURCES.txt' Maybe try: sudo apt-get install pandoc See http://johnmacfarlane.net/pandoc/installing.html for installation options --------------------------------------------------------------- /usr/local/lib/python3.4/dist-packages/setuptools/dist.py:352: UserWarning: Normalizing '18.01.10' to '18.1.10' normalized_version, Source in /tmp/pip-build-cfplh53p/cppimport has version 18.1.10, which satisfies requirement cppimport==18.1.10 from https://pypi.python.org/packages/4d/cf/690066fd4bcf36599497e2a0b22fcfefa35b0bd1c8924b74a42f3f41e12e/cppimport-18.1.10.tar.gz#md5=210b6c60c8d7fac3504af59685316ad9 Building wheels for collected packages: cppimport Running setup.py bdist_wheel for cppimport: started Destination directory: /tmp/tmp0atzlygbpip-wheel- Running command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-cfplh53p/cppimport/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmp0atzlygbpip-wheel- Maybe try: sudo apt-get install pandoc See http://johnmacfarlane.net/pandoc/installing.html for installation options --------------------------------------------------------------- ##### If you've used cppimport version 0.0.*, some new features for you! Compiler arguments, multiple source files, bug fixes! Read on. # Import C or C++ files directly from Python! Let's try it out. First, if you're on Linux or OS X, install with the terminal command `pip install cppimport`. Most cppimport users combine it with [pybind11](https://github.com/pybind/pybind11), but you can use a range of methods to create your Python extensions. Raw C extensions, Boost.Python, SWIG all work. Let's look at a simple C++ extension: ```c++ /*cppimport <% setup_pybind11(cfg) %> */ #include namespace py = pybind11; int square(int x) { return x * x; } PYBIND11_PLUGIN(somecode) { pybind11::module m("somecode", "auto-compiled c++ extension"); m.def("square", &square); return m.ptr(); } ``` Save this code as `somecode.cpp`. Open a python interpreter and run these lines [\[1\]](#notes): ```python >>> import cppimport >>> somecode = cppimport.imp("somecode") #This will pause for a moment to compile the module >>> somecode.square(9) 81 ``` I'm a big fan of the workflow that this enables, where you can edit both C++ files and Python and recompilation happens transparently. # I want things to be even easier! (Python import hook) Modify the first section of the .cpp file and add "cppimport" on the first line of the file. This MUST be on the first line. This is explained further down. ```c++ /*cppimport <% setup_pybind11(cfg) %> */ ``` Then import the file using the import hook: ```python >>> import cppimport.import_hook >>> import somecode #This will pause for a moment to compile the module >>> somecode.square(9) 81 ``` # What's actually going on? **The technical description:** cppimport looks for a C or C++ source file that matches the requested module. If such a file exists, the file is first run through the Mako templating system. The compilation options produced by the Mako pass are then use to compile the file as a Python extension. The extension (shared library) that is produced is placed in the same folder as the C++ source file. Then, the extension is loaded. **Simpler language please:** Sometimes Python just isn't fast enough. Or you have existing code in a C++ library. So, you write a Python *extension module*, a library of compiled code. I recommend [pybind11](https://github.com/pybind/pybind11) for C++ to Python bindings or [cffi](https://cffi.readthedocs.io/en/latest/) for C to Python bindings. I've done this a lot over the years. But, I discovered that my productivity goes through the floor when my development process goes from *Edit -> Test* in just Python to *Edit -> Compile -> Test* in Python plus C++. So, `cppimport` combines the process of compiling and importing an extension in Python so that you can type `modulename = cppimport.imp("modulename")` and not have to worry about multiple steps. Internally, `cppimport` looks for a file `modulename.cpp`. If one is found, it's run through the Mako templating system to gather compiler options, then it's compiled and loaded as an extension module. Note that because of the Mako pre-processing, the comments around the configuration block may be omitted. ### Recompilation only happens when necessary: Compilation should only happen the first time the module is imported. The C++ source is compared with a checksum on each import to determine if the file has changed. Additional dependencies (header files!) can be tracked by adding to the Mako header: ``` cfg['dependencies'] = ['file1.h', 'file2.h'] ``` ### I need to set the compiler or linker args! ``` cfg['linker_args'] = ['...'] cfg['compiler_args'] = ['...'] cfg['libraries'] = ['...'] cfg['include_dirs'] = ['...'] ``` For example, to use C++11, add: ``` <% cfg['compiler_args'] = ['-std=c++11'] %> ``` ### I want multiple source files for one extension! ``` cfg['sources'] = ['...'] ``` ### I need more output! Calling `cppimport.set_quiet(False)` will result in output that will be helpful in debugging compile errors. ### Sometimes I need to force a rebuild even when the checksum matches Call `cppimport.force_rebuild()` before running `cppimport.imp(...)`. ### I want incremental compiles on extensions with multiple sources. (For the uninitiated, incremental compilation involves only recompiling those source files that have changed or include headers that have changed.) cppimport is built on top of the setuptools and distutils, the standard library for python packaging and distribution. Unfortunately, setuptools does not support incremental compilation. I recommend following the suggestions on [this SO answer](http://stackoverflow.com/questions/11013851/speeding-up-build-process-with-distutils). That is: 1. Use ccache to (massively) reduce the cost of rebuilds 2. Enable parallel compilation. This can be done with `cfg['parallel'] = True` in the C++ file's configuration header. ### I need information about filepaths in my module configuration code! The module name is available as the `fullname` variable and the C++ module file is available as `filepath`. For example, ``` <% module_dir = os.path.dirname(filepath) %> ``` ### Why does the import hook need "cppimport" on the first line of the .cpp file? Modifying the Python import system is a global modification and thus affects all imports from any other package. As a result, to avoid accidentally breaking another package, the import hook uses an "opt in" system where C and C++ files can specify they are meant to be used with cppimport by having a comment including the phrase "cppimport" on the first line of the file. ### Windows? I don't know if `cppimport` works on Windows. If you're on Windows, try it out and I'll happily accept a pull request for any issues that you fix. I have reports that `cppimport` works on Windows with Python 3.6 and Visual C++ 2015 Build Tools. # cppimport uses the MIT License /usr/local/lib/python3.4/dist-packages/setuptools/dist.py:352: UserWarning: Normalizing '18.01.10' to '18.1.10' normalized_version, running bdist_wheel running build running build_py creating build creating build/lib creating build/lib/cppimport copying cppimport/importer.py -> build/lib/cppimport copying cppimport/filepaths.py -> build/lib/cppimport copying cppimport/find.py -> build/lib/cppimport copying cppimport/checksum.py -> build/lib/cppimport copying cppimport/templating.py -> build/lib/cppimport copying cppimport/__init__.py -> build/lib/cppimport copying cppimport/import_hook.py -> build/lib/cppimport copying cppimport/cpprun.py -> build/lib/cppimport copying cppimport/build_module.py -> build/lib/cppimport copying cppimport/config.py -> build/lib/cppimport installing to build/bdist.linux-armv7l/wheel running install running install_lib creating build/bdist.linux-armv7l creating build/bdist.linux-armv7l/wheel creating build/bdist.linux-armv7l/wheel/cppimport copying build/lib/cppimport/importer.py -> build/bdist.linux-armv7l/wheel/cppimport copying build/lib/cppimport/filepaths.py -> build/bdist.linux-armv7l/wheel/cppimport copying build/lib/cppimport/find.py -> build/bdist.linux-armv7l/wheel/cppimport copying build/lib/cppimport/checksum.py -> build/bdist.linux-armv7l/wheel/cppimport copying build/lib/cppimport/templating.py -> build/bdist.linux-armv7l/wheel/cppimport copying build/lib/cppimport/__init__.py -> build/bdist.linux-armv7l/wheel/cppimport copying build/lib/cppimport/import_hook.py -> build/bdist.linux-armv7l/wheel/cppimport copying build/lib/cppimport/cpprun.py -> build/bdist.linux-armv7l/wheel/cppimport copying build/lib/cppimport/build_module.py -> build/bdist.linux-armv7l/wheel/cppimport copying build/lib/cppimport/config.py -> build/bdist.linux-armv7l/wheel/cppimport running install_egg_info running egg_info writing top-level names to cppimport.egg-info/top_level.txt writing entry points to cppimport.egg-info/entry_points.txt writing dependency_links to cppimport.egg-info/dependency_links.txt writing requirements to cppimport.egg-info/requires.txt writing cppimport.egg-info/PKG-INFO reading manifest file 'cppimport.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' writing manifest file 'cppimport.egg-info/SOURCES.txt' Copying cppimport.egg-info to build/bdist.linux-armv7l/wheel/cppimport-18.1.10-py3.4.egg-info running install_scripts creating build/bdist.linux-armv7l/wheel/cppimport-18.1.10.dist-info/WHEEL Running setup.py bdist_wheel for cppimport: finished with status 'done' Stored in directory: /tmp/tmptt_75d64 Successfully built cppimport Cleaning up... Removing source in /tmp/pip-build-cfplh53p/cppimport