caffe icon indicating copy to clipboard operation
caffe copied to clipboard

Cannot make Python wrapper

Open ashkan-leo opened this issue 11 years ago • 6 comments

I am trying to build the Python wrapper using pycaffe, but the build fails every time. Here is the error message I get:

`python/caffe/_caffe.cpp:209:1: warning: unused typedef 'assertion' [-Wunused-local-typedef]
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(SolveOverloads, Solve, 0, 1);
^
/usr/local/include/boost/python/detail/defaults_gen.hpp:375:5: note: expanded from macro 'BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS'
    BOOST_PYTHON_GEN_MEM_FUNCTION_STUB(                                                     \
    ^
/usr/local/include/boost/python/detail/defaults_gen.hpp:276:9: note: expanded from macro 'BOOST_PYTHON_GEN_MEM_FUNCTION_STUB'
        BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args + 1, n_dflts)            \
        ^
/usr/local/include/boost/python/detail/defaults_gen.hpp:216:46: note: expanded from macro 'BOOST_PYTHON_OVERLOAD_CONSTRUCTORS'
                N,n_args>::too_many_keywords assertion;                                     \
                                             ^
python/caffe/_caffe.cpp:209:1: warning: unused typedef 'assertion' [-Wunused-local-typedef]
/usr/local/include/boost/python/detail/defaults_gen.hpp:375:5: note: expanded from macro 'BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS'
    BOOST_PYTHON_GEN_MEM_FUNCTION_STUB(                                                     \
    ^
/usr/local/include/boost/python/detail/defaults_gen.hpp:276:9: note: expanded from macro 'BOOST_PYTHON_GEN_MEM_FUNCTION_STUB'
        BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args + 1, n_dflts)            \
        ^
/usr/local/include/boost/python/detail/defaults_gen.hpp:225:46: note: expanded from macro 'BOOST_PYTHON_OVERLOAD_CONSTRUCTORS'
                N,n_args>::too_many_keywords assertion;                                     \
                                             ^
2 warnings generated.
Undefined symbols for architecture x86_64:
  "_PyUnicode_FromStringAndSize", referenced from:
      boost::python::str::str<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in _caffe-0418bb.o
      boost::python::detail::no_proxy_helper<std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, boost::python::detail::final_vector_derived_policies<std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, false>, boost::python::detail::container_element<std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, unsigned long, boost::python::detail::final_vector_derived_policies<std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, false> >, unsigned long>::base_get_item_(boost::python::back_reference<std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&> const&, _object*) in _caffe-0418bb.o
      boost::python::objects::caller_py_function_impl<boost::python::detail::caller<boost::python::objects::iterator_range<boost::python::return_value_policy<boost::python::return_by_value, boost::python::default_call_policies>, std::__1::__wrap_iter<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*> >::next, boost::python::return_value_policy<boost::python::return_by_value, boost::python::default_call_policies>, boost::mpl::vector2<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, boost::python::objects::iterator_range<boost::python::return_value_policy<boost::python::return_by_value, boost::python::default_call_policies>, std::__1::__wrap_iter<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*> >&> > >::operator()(_object*, _object*) in _caffe-0418bb.o
  "boost::python::detail::init_module(PyModuleDef&, void (*)())", referenced from:
      _PyInit__caffe in _caffe-0418bb.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [python/caffe/_caffe.so] Error 1`

It appears that something is wrong with boost. I am using OS X 10.11 with Anaconda Python 3.4.3. Anyone have any idea what is causing this problem?

ashkan-leo avatar Nov 04 '15 02:11 ashkan-leo

Did you include /path/to/caffe/python in your PYTHONPATH?

xxw345 avatar Nov 04 '15 03:11 xxw345

This is more likely to be a issue with libstdc++/libc++ in OSX. You will have to match the lib for which boost is linked against. You can try to add -stdlib=libstdc++ to CXX/LINKFLAGS.

happyharrycn avatar Nov 20 '15 19:11 happyharrycn

I get this error when trying to install caffe on python 3. When I compile on python 2.7 everything seems to work fine.

@happyharrycn I reinstalled boost and boost-python with --c++11 and --with-python3 options. Then tried to compile pycaffe with both the anaconda python3 and homebrew python3 and still continued to get the error about _PyUnicode_FromStringAndSize.

zenlambda avatar Nov 29 '15 13:11 zenlambda

I am having this issue now too. Opencv3, boost 1.59, caffe 0.14, python3

Undefined symbols for architecture x86_64:
  "_PyUnicode_FromStringAndSize", referenced from:
      boost::python::str::str<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in _caffe-bbdd85.o
      boost::python::detail::no_proxy_helper<std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, boost::python::detail::final_vector_derived_policies<std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, false>, boost::python::detail::container_element<std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, unsigned long, boost::python::detail::final_vector_derived_policies<std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, false> >, unsigned long>::base_get_item_(boost::python::back_reference<std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&> const&, _object*) in _caffe-bbdd85.o
      boost::python::objects::caller_py_function_impl<boost::python::detail::caller<boost::python::objects::iterator_range<boost::python::return_value_policy<boost::python::return_by_value, boost::python::default_call_policies>, std::__1::__wrap_iter<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*> >::next, boost::python::return_value_policy<boost::python::return_by_value, boost::python::default_call_policies>, boost::mpl::vector2<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, boost::python::objects::iterator_range<boost::python::return_value_policy<boost::python::return_by_value, boost::python::default_call_policies>, std::__1::__wrap_iter<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*> >&> > >::operator()(_object*, _object*) in _caffe-bbdd85.o
  "boost::python::detail::init_module(PyModuleDef&, void (*)())", referenced from:
      _PyInit__caffe in _caffe-bbdd85.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [python/caffe/_caffe.so] Error 1

MichaMucha avatar Dec 26 '15 19:12 MichaMucha

I am also having this issue (python3, boost 1.60 (installed with --c++11), opencv 2.4.12).

Has anyone managed to solve this yet?

Edit: thanks to @zenlambda 's comment, I tried to compile with python 2.7 and this did work. However I would still like to get it working with 3.5 if possible!

jt86 avatar Mar 15 '16 11:03 jt86

brew reinstall boost-python --with-python3 --without-python

yukang2017 avatar Oct 11 '17 15:10 yukang2017