visp
visp copied to clipboard
Error when building python bindings in ubuntu 22.04
I've been trying to build the library with python bindings as described in the docs. However, I am getting some errors regarding the definition of numpy arrays:
115.9 [ 97%] Building CXX object modules/python/bindings/CMakeFiles/_visp.dir/src/sensor.cpp.o
119.2 /app/visp-build-dir/modules/python/bindings/src/core.cpp: In function 'void init_submodule_core(pybind11::module_&)':
119.2 /app/visp-build-dir/modules/python/bindings/src/core.cpp:1690:61: error: 'NpyArray' was not declared in this scope; did you mean 'visp::cnpy::NpyArray'?
119.2 1690 | submodule.def("npz_load", static_cast<std::map<std::string, NpyArray> (*)(std::string)>(&visp::cnpy::npz_load), py::arg("fname"));
119.2 | ^~~~~~~~
119.2 | visp::cnpy::NpyArray
119.2 In file included from /app/visp-build-dir/modules/python/bindings/src/core.cpp:88:
119.2 /app/visp/modules/core/include/visp3/core/vpIoTools.h:82:8: note: 'visp::cnpy::NpyArray' declared here
119.2 82 | struct NpyArray
119.2 | ^~~~~~~~
119.2 /app/visp-build-dir/modules/python/bindings/src/core.cpp:1690:69: error: template argument 2 is invalid
119.2 1690 | submodule.def("npz_load", static_cast<std::map<std::string, NpyArray> (*)(std::string)>(&visp::cnpy::npz_load), py::arg("fname"));
119.2 | ^
119.2 /app/visp-build-dir/modules/python/bindings/src/core.cpp:1690:69: error: template argument 4 is invalid
119.2 /app/visp-build-dir/modules/python/bindings/src/core.cpp:1690:71: error: expected '>' before '(' token
119.2 1690 | submodule.def("npz_load", static_cast<std::map<std::string, NpyArray> (*)(std::string)>(&visp::cnpy::npz_load), py::arg("fname"));
119.2 | ^
119.2 /app/visp-build-dir/modules/python/bindings/src/core.cpp:1690:73: error: expected primary-expression before ')' token
119.2 1690 | submodule.def("npz_load", static_cast<std::map<std::string, NpyArray> (*)(std::string)>(&visp::cnpy::npz_load), py::arg("fname"));
119.2 | ^
119.2 /app/visp-build-dir/modules/python/bindings/src/core.cpp:1690:86: error: expected primary-expression before ')' token
119.2 1690 | submodule.def("npz_load", static_cast<std::map<std::string, NpyArray> (*)(std::string)>(&visp::cnpy::npz_load), py::arg("fname"));
119.2 | ^
119.5 [ 97%] Building CXX object modules/python/bindings/CMakeFiles/_visp.dir/src/ar.cpp.o
I created a Dockerfile to reproduce the issue:
FROM ubuntu:22.04
WORKDIR /app
ENV DEBIAN_FRONTEND=noninteractive
ENV VISP_WS=/app/visp-ws
# Install latest cmake (3.24), cmake > 3.19 needed for python bindings
RUN apt-get update \
&& apt-get -y install build-essential \
&& apt-get install -y wget \
&& rm -rf /var/lib/apt/lists/* \
&& wget https://github.com/Kitware/CMake/releases/download/v3.24.1/cmake-3.24.1-Linux-x86_64.sh \
-q -O /tmp/cmake-install.sh \
&& chmod u+x /tmp/cmake-install.sh \
&& mkdir /opt/cmake-3.24.1 \
&& /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-3.24.1 \
&& rm /tmp/cmake-install.sh \
&& ln -s /opt/cmake-3.24.1/bin/* /usr/local/bin
# Update and install software-properties-common (for add-apt-repository)
RUN apt-get update -y && apt-get install -y software-properties-common
# Add the deadsnakes PPA, which contains newer Python versions
RUN add-apt-repository ppa:deadsnakes/ppa
# # Install git
RUN apt-get install -y git
# Install Python 3.11
RUN apt-get install -y python3.11 python3.11-venv python3.11-dev
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1
RUN python3 -m ensurepip
RUN python3 -m pip install --upgrade pip
# install venv
RUN pip3 install virtualenv
RUN cd /opt && virtualenv venv --system-site-packages
# Enable venv
ENV PATH="/opt/venv/bin:$PATH"
RUN pip install pybind11
RUN git clone https://github.com/lagadic/visp.git
RUN mkdir visp-build-dir && cd visp-build-dir && cmake ../visp -D pybind11_DIR=/opt/venv/lib/python3.11/site-packages/pybind11/share/cmake/pybind11
RUN cd visp-build-dir && make -j$(nproc) visp_python_bindings
Any help/hint would be highly appreciated, thanks!!
Hi,
Thanks for the feedback!
I believe we have already solved this issue in the following pull request: #1316 that contains several improvements to the bindings build process.
If you wish to try, you can clone this branch and try from a fresh cmake build. Another PR, #1312 , is in the works to introduce a better documentation for the installation process.
Cheers, Sam