Hi All,
I am having some difficultly getting boost python to work on OS X with Anaconda Python 3.5.
I have Anaconda Python installed. I also installed boost-python via the conda command (also tried with home-brew).
I have a very simple class shown below.
I am able to build using the following: g++ -shared -stdlib=libstdc++ -I/Users/Jon/anaconda/pkgs/python-3.5.1-0/include/python3.5m -L/Users/Jon/anaconda/pkgs/python-3.5.1-0/lib -L/Users/Jon/anaconda/pkgs/boost-1.60.0-py35_0/lib -lboost_python3 -lpython3.5m -L. -fpic -o hello_ext.so hello_ext.cpp
I then import hello_ext into a python shell and am able to run the greet function. However, when I try instantiating the World class like a=hello_ext.World(), I am met with:
TypeError: __init__() should return None, not 'NoneType'
From what I understand, this means there is incompatibility with the python version linked into boost_python.
When I do an otool -L on libboost_python3.dylib, I don't see any reference to a particular python library.
Any help in troubleshooting this would be greatly appreciated.
Here is the c++ class I am trying to test:
#include <boost/python.hpp>
#include <string>
#include <map>
char const* greet()
{
return "hello, world";
}
class World {
public:
// Constructors - set a-f to default values.
World(){}
//void SetParameters(std::map<std::string, double> &);
void SetParameters(std::map<std::string, double> const& params) {
// Code to iterate over the map, and set any found key/value pairs to their
// corresponding variable. i.e.- "a" --> 2.0, would set myClass::a to 2.0
}
private:
double a, b, c, d, e, f;
};
BOOST_PYTHON_MODULE(hello_ext)
{
using namespace boost::python;
def("greet", greet);
class_<World>("World")
.def("SetParameters", &World::SetParameters)
;
}