clang++ - Boost.Python Error when use class -


i got error typeerror: __init__() should return none, not 'nonetype' when use class in boost.python (i run simple "hello, world").

environment

  • macos sierra
  • i use pyenv-virtualenv
    • python 3.6.0
    • $ source activate py36
  • i installed boost-python via homebrew
    1. $pyenv global py36
    2. $brew install boost
    3. $brew install boost-python --with-python3

code

this simple code tried (test.cpp).

#include <boost/python.hpp> using namespace boost::python;  int main(){  }  class accumulator { public:     int operator()(int v) {         v_ += v;         return v_;     }      int value() const {         return v_;     }  private:     int v_; };  boost_python_module(test) {      class_<accumulator>("accumulator")         .def("__call__",              &accumulator::operator())         .add_property("value", &accumulator::value)         ; } 

makefile

cc = clang++ -std=c++11 -stdlib=libc++ python_root = /usr/local/var/pyenv/versions/3.6.0 python = -lpython3.6m -lboost_python3  # location of boost python include files , library  boost_inc = /usr/local/cellar/boost-python/1.64.0/include boost_lib = /usr/local/cellar/boost-python/1.64.0/lib  # compile mesh classes target = test  $(target).so: $(target).o     $(cc) $(target).o $(python) -i$(python_root)/include/python3.6m  -l$(boost_lib) -l$(python_root)/lib  -o $(target).so  $(target).o: $(target).cpp     $(cc)  -i$(python_root)/include/python3.6m -i$(boost_inc) -c $(target).cpp 

compile

$ make clang++ -std=c++11 -stdlib=libc++  -i/usr/local/var/pyenv/versions/3.6.0/include/python3.6m -i/usr/local/cellar/boost-python/1.64.0/include -c test.cpp clang++ -std=c++11 -stdlib=libc++ test.o -lpython3.6m -lboost_python3 -i/usr/local/var/pyenv/versions/3.6.0/include/python3.6m  -l/usr/local/cellar/boost-python/1.64.0/lib -l/usr/local/var/pyenv/versions/3.6.0/lib  -o test.so  $ python python 3.6.0 (default, dec 28 2016, 23:31:45) [gcc 4.2.1 compatible apple llvm 8.0.0 (clang-800.0.42.1)] on darwin type "help", "copyright", "credits" or "license" more information. >>> import test >>> = test.accumulator() traceback (most recent call last):   file "<stdin>", line 1, in <module> typeerror: __init__() should return none, not 'nonetype' 

i did same question in japanese. translate solution if in either 1 of them.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -