Boost Python

0 views
Skip to first unread message

jonle...@gmail.com

unread,
May 24, 2016, 7:36:59 PM5/24/16
to Anaconda - Public
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)
    ;

}

Stuart Berg

unread,
May 25, 2016, 9:19:56 AM5/25/16
to anac...@continuum.io
Hi Jon,

I'm not sure if this is related to your problem, but I think it's generally a bad idea to use the library files from the 'pkgs' directory.  Instead, install python and boost-python into an environment, and use the files from the environment.

That is, create an environment:

conda create -n my-env python=3.5 boost

Then, instead of -L/Users/Jon/anaconda/pkgs/boost-1.60.0-py35_0/lib, use
L/Users/Jon/anaconda/envs/my-env/boost-1.60.0-py35_0/lib

Again, I'm not sure that this will fix the issue, but it's at least a good place to start.

Best,
Stuart


--
Anaconda Community Support Group Brought to you by Continuum Analytics
---
You received this message because you are subscribed to the Google Groups "Anaconda - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to anaconda+u...@continuum.io.
To post to this group, send email to anac...@continuum.io.
Visit this group at https://groups.google.com/a/continuum.io/group/anaconda/.

Jon Lederman

unread,
May 25, 2016, 9:24:06 AM5/25/16
to anac...@continuum.io
Thanks.  I will try this and let you know.  Where is the best place to get support?

Sent from my iPhone
You received this message because you are subscribed to a topic in the Google Groups "Anaconda - Public" group.
To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/anaconda/YMxofEk-Db0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to anaconda+u...@continuum.io.

Jon Lederman

unread,
May 25, 2016, 12:40:40 PM5/25/16
to anac...@continuum.io
Hi,

I tried your suggestion and it still doesn’t work.  Shouldn’t boost-python be linked to a specific python version.  When I do otool -L on libboost_python3.dylib, I see:
(my-env)Jons-MacBook-Pro-3:boost_python_test Jon$ otool -L /Users/Jon/anaconda/envs/my-env/lib/libboost_python3.dylib
/Users/Jon/anaconda/envs/my-env/lib/libboost_python3.dylib:
@rpath/./libboost_python3.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)

I don’t see any reference to a specific python library.  Shouldn’t there be one?


On May 25, 2016, at 9:19 AM, Stuart Berg <stuar...@gmail.com> wrote:

/Users/Jon/anaconda/envs/my-env/boost-1.60.0-py35_0/lib

Stuart Berg

unread,
May 25, 2016, 8:45:32 PM5/25/16
to anac...@continuum.io
>I don’t see any reference to a specific python library.  Shouldn’t there be one?

Well dang, you're totally right.  Now I'm confused.  For instance, I use my own conda package for boost.  I see this:

$ otool -L libboost_python.dylib
libboost_python.dylib:
    @rpath/./libboost_python-mt.dylib (compatibility version 0.0.0, current version 0.0.0)
    @rpath/libpython2.7.dylib (compatibility version 2.7.0, current version 2.7.0)
    @rpath/./libstdc++.6.dylib (compatibility version 7.0.0, current version 7.19.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)
    @rpath/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)

As you can see, libpython is present.  But when I install Anaconda's boost package, I see the same output you showed (libpython is missing).

My build probably won't meet your needs because I use python 2.7 and boost 1.55, but you're free to give it a try if you want:

conda install -c ilastik boost=1.55.0


I guess one of the continuum maintainers needs to examine the boost recipe and figure out why it isn't linking against python as expected.  (Or maybe I'm missing something...)

-Stuart
Reply all
Reply to author
Forward
0 new messages