Pangolin
Pangolin copied to clipboard
‘PyUnicode_AsUTF8’ was not declared in this scope when building
Trying to install Pangolin using Build instructions provided and get this error. Making a modification to the pyinterpreter.cpp as suggested gives me other errors. Cmake version 3.23.2 and Ubuntu 18.04. Tried instructions here which did not work either.
[ 54%] Building CXX object CMakeFiles/pango_python.dir/components/pango_python/src/pyinterpreter.cpp.o
In file included from /home/user/Pangolin/components/pango_python/src/pyinterpreter.cpp:27:0:
/home/user/Pangolin/components/pango_python/include/pangolin/python/pyinterpreter.h:40:7: warning: ‘pangolin::PyInterpreter’ declared with greater visibility than the type of its field ‘pangolin::PyInterpreter::guard’ [-Wattributes]
class PyInterpreter : public InterpreterInterface
^~~~~~~~~~~~~
/home/user/Pangolin/components/pango_python/include/pangolin/python/pyinterpreter.h:40:7: warning: ‘pangolin::PyInterpreter’ declared with greater visibility than the type of its field ‘pangolin::PyInterpreter::pycompleter’ [-Wattributes]
/home/user/Pangolin/components/pango_python/include/pangolin/python/pyinterpreter.h:40:7: warning: ‘pangolin::PyInterpreter’ declared with greater visibility than the type of its field ‘pangolin::PyInterpreter::pycomplete’ [-Wattributes]
/home/user/Pangolin/components/pango_python/src/pyinterpreter.cpp: In member function ‘std::__cxx11::string pangolin::PyInterpreter::ToString(const pybind11::object&)’:
/home/user/Pangolin/components/pango_python/src/pyinterpreter.cpp:113:24: error: ‘PyUnicode_AsUTF8’ was not declared in this scope
return std::string(PyUnicode_AsUTF8(pystr.ptr()));
^~~~~~~~~~~~~~~~
/home/user/Pangolin/components/pango_python/src/pyinterpreter.cpp:113:24: note: suggested alternative: ‘PyUnicode_Type’
return std::string(PyUnicode_AsUTF8(pystr.ptr()));
^~~~~~~~~~~~~~~~
PyUnicode_Type
/home/user/Pangolin/components/pango_python/src/pyinterpreter.cpp: In member function ‘virtual std::vector<std::__cxx11::basic_string<char> > pangolin::PyInterpreter::Complete(const string&, int)’:
/home/user/Pangolin/components/pango_python/src/pyinterpreter.cpp:156:37: error: ‘PyUnicode_AsUTF8’ was not declared in this scope
std::string res_str(PyUnicode_AsUTF8(result));
^~~~~~~~~~~~~~~~
/home/user/Pangolin/components/pango_python/src/pyinterpreter.cpp:156:37: note: suggested alternative: ‘PyUnicode_Type’
std::string res_str(PyUnicode_AsUTF8(result));
^~~~~~~~~~~~~~~~
PyUnicode_Type
CMakeFiles/pango_python.dir/build.make:75: recipe for target 'CMakeFiles/pango_python.dir/components/pango_python/src/pyinterpreter.cpp.o' failed
make[2]: *** [CMakeFiles/pango_python.dir/components/pango_python/src/pyinterpreter.cpp.o] Error 1
CMakeFiles/Makefile2:701: recipe for target 'CMakeFiles/pango_python.dir/all' failed
make[1]: *** [CMakeFiles/pango_python.dir/all] Error 2
Makefile:135: recipe for target 'all' failed
make: *** [all] Error 2
I met the same problem.
Well. If you do not use python with it, the solution I have here is that comment out the ${CMAKE_CURRENT_LIST_DIR}/src/pyinterpreter.cpp in Pangolin/components/pango_python/CMakeLists.txt. It should be fine.
It looks like PyUnicode_AsUTF8 is only available with python 3.X and I guess you're using 2.X. You could switch to python3 or you could introduce a guard here https://github.com/stevenlovegrove/Pangolin/blob/master/components/pango_python/src/pyinterpreter.cpp#L113 and https://github.com/stevenlovegrove/Pangolin/blob/master/components/pango_python/src/pyinterpreter.cpp#L155 based on version.