Pybind11 C++ python standard output from ostream (Jupyter notebook)

254 Views Asked by At

I have a problem with displaying an output from show() function and Jupyter notebook. This is small example of working code:

#include <pybind11/stl.h>
#include <pybind11/pybind11.h> 
#include <pybind11/iostream.h> 
#include <iostream>       
#include <stdio.h>   
#include <stdlib.h>       
#include <algorithm>
#include <vector>
#include <limits>
#include <math.h>

using namespace std;
namespace py = pybind11;

void show(std::string prompt, double x){
  std::cout << prompt << " " << x << '\n';
}


PYBIND11_MODULE(appname, handle) {

    handle.def("show", (void (*)(std::string, double)) &show);
}

When you run the following command in python from terminal everything works fine. However, it shows nothing when using Jupyter notebook.

import appname    
appname.show("number:", 5.0)

The problem is described here (https://pybind11.readthedocs.io/en/stable/advanced/pycpp/utilities.html) but I can't implement it correctly.

Thanks for any suggestions.

0

There are 0 best solutions below