Dockerfile: Python.h: No such file or directory - docker

I have a simple dockerfile that I am using to run containers on AWS, I'm hitting an issue though when installing s3fs, which is strange since I've used this snippet in previous dockerfiles without issue.
Is it something with the distribution?
Error:
multidict/_multidict.c:1:10: fatal error: Python.h: No such file or directory
Dockerfile:
FROM amazonlinux:latest
RUN yum -y install which unzip aws-cli \
&& yum install -y python3-pip python3 python3-setuptools \
&& yum install -y tar.x86_64 \
&& DEBIAN_FRONTEND=noninteractive yum install -y ksh
RUN pip3 install boto3 \
&& yum install -y gcc \
&& pip3 install s3fs
Here is the output log:
Installing collected packages: fsspec, docutils, botocore, typing-extensions, aioitertools, wrapt, attrs, chardet, multidict, async-timeout, idna, yarl, aiohttp, aiobotocore, s3fs
Found existing installation: botocore 1.19.11
Uninstalling botocore-1.19.11:
Successfully uninstalled botocore-1.19.11
Running setup.py install for wrapt: started
Running setup.py install for wrapt: finished with status 'done'
Running setup.py install for multidict: started
Running setup.py install for multidict: finished with status 'error'
Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-l35mgnnl/multidict/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-7d6e5wlf-record/install-record.txt --single-version-externally-managed --compile:
**********************
* Accellerated build *
**********************
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.7
creating build/lib.linux-x86_64-3.7/multidict
copying multidict/_abc.py -> build/lib.linux-x86_64-3.7/multidict
copying multidict/__init__.py -> build/lib.linux-x86_64-3.7/multidict
copying multidict/_multidict_base.py -> build/lib.linux-x86_64-3.7/multidict
copying multidict/_multidict_py.py -> build/lib.linux-x86_64-3.7/multidict
copying multidict/_compat.py -> build/lib.linux-x86_64-3.7/multidict
running egg_info
writing multidict.egg-info/PKG-INFO
writing dependency_links to multidict.egg-info/dependency_links.txt
writing top-level names to multidict.egg-info/top_level.txt
reading manifest file 'multidict.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no previously-included files matching '*.pyc' found anywhere in distribution
warning: no previously-included files found matching 'multidict/_multidict.html'
warning: no previously-included files found matching 'multidict/*.so'
warning: no previously-included files found matching 'multidict/*.pyd'
warning: no previously-included files found matching 'multidict/*.pyd'
no previously-included directories found matching 'docs/_build'
writing manifest file 'multidict.egg-info/SOURCES.txt'
copying multidict/__init__.pyi -> build/lib.linux-x86_64-3.7/multidict
copying multidict/_multidict.c -> build/lib.linux-x86_64-3.7/multidict
copying multidict/py.typed -> build/lib.linux-x86_64-3.7/multidict
creating build/lib.linux-x86_64-3.7/multidict/_multilib
copying multidict/_multilib/defs.h -> build/lib.linux-x86_64-3.7/multidict/_multilib
copying multidict/_multilib/dict.h -> build/lib.linux-x86_64-3.7/multidict/_multilib
copying multidict/_multilib/istr.h -> build/lib.linux-x86_64-3.7/multidict/_multilib
copying multidict/_multilib/iter.h -> build/lib.linux-x86_64-3.7/multidict/_multilib
copying multidict/_multilib/pair_list.h -> build/lib.linux-x86_64-3.7/multidict/_multilib
copying multidict/_multilib/views.h -> build/lib.linux-x86_64-3.7/multidict/_multilib
running build_ext
building 'multidict._multidict' extension
creating build/temp.linux-x86_64-3.7
creating build/temp.linux-x86_64-3.7/multidict
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python3.7m -c multidict/_multidict.c -o build/temp.linux-x86_64-3.7/multidict/_multidict.o -O2 -std=c99 -Wall -Wsign-compare -Wconversion -fno-strict-aliasing -pedantic
multidict/_multidict.c:1:10: fatal error: Python.h: No such file or directory
#include "Python.h"
^~~~~~~~~~
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-l35mgnnl/multidict/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-7d6e5wlf-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-l35mgnnl/multidict/
The command '/bin/sh -c pip3 install boto3 && yum install -y gcc && pip3 install s3fs' returned a non-zero code: 1
Any help is much appreciated!

You should add python3-devel package that contains absent headers.
FROM amazonlinux:latest
RUN yum -y install which unzip aws-cli \
&& yum install -y python3-pip python3 python3-setuptools \
&& yum install -y python3-devel.x86_64 \
&& yum install -y tar.x86_64 \
&& DEBIAN_FRONTEND=noninteractive yum install -y ksh
RUN pip3 install boto3 \
&& yum install -y gcc \
&& pip3 install s3fs

Related

How to run bdist_wheel on Ubuntu 18.04?

I've got a small Dockerfile where I'm trying to get to a point where I can RUN pip3 bdist_wheel successfully. That is, without getting this error:
unknown command "bdist_wheel" - maybe you meant "wheel"
I've tried installing everything mentioned in this answer, but no luck.
Minimal repro Dockerfile and docker build output:
FROM ubuntu:18.04
RUN apt-get update \
&& apt-get install -qyy -o APT::Install-Recommends=false -o APT::Install-Suggests=false \
file \
gcc \
python3 \
python3-dev \
python3-pip \
python3-setuptools \
python3-venv \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN pip3 install --cache-dir=/tmp/pipcache --upgrade pip && rm -rf /tmp/pipcache
RUN pip install --cache-dir=/tmp/pipcache poetry && rm -rf /tmp/pipcache
WORKDIR /src/app
RUN poetry new .
RUN poetry add gevent
The most relevant part of the output is of course
error: invalid command 'bdist_wheel'
First, some notes to the error: invalid command 'bdist_wheel' output. When running pip install <pkgname>, pip will try to find a prebuilt wheel that matches your target platform. If it doesn't find one, it tries to build a wheel itself -- the source dist is downloaded and pip wheel is run to produce the wheel. On success, the built wheel is installed. On any failure (the wheel package not installed, python setup.py bdist_wheel failed or whatever), pip will fallback to the second option, which is the distutils installation method: running python setup.py install over the unpacked source dist. This is what you can observe in the log you posted:
Failed building wheel for gevent
...
Running setup.py install for gevent: started
Only when the setup.py install also fails, the installation is failed unconditionally. So while pip can't indeed build the wheel b/c the wheel package is not installed, it is not an issue for the failing installation. You can fix this by adding wheel to development packages:
RUN poetry add --dev wheel
RUN poetry add gevent
but this is an optional thing and won't affect the build result.
Now, to the real error:
Running '(cd "/tmp/pip-build-ek9pxyw2/gevent/deps/libev" && sh ./configure -C > configure-output.txt )' in /tmp/pip-build-ek9pxyw2/gevent
config.status: error: in `/tmp/pip-build-ek9pxyw2/gevent/deps/libev':
config.status: error: Something went wrong bootstrapping makefile fragments
for automatic dependency tracking. Try re-running configure with the
'--disable-dependency-tracking' option to at least be able to build
the package (albeit without support for automatic dependency tracking).
See `config.log' for more details
Something went wrong bootstrapping makefile fragments usually means that you're missing make. Install it in addition to the rest:
RUN apt install -y make
After doing that and rerunning the build, I've got the last error
error: src/gevent/libev/corecext.c: No such file or directory
This is because gevent needs Cython for generating the C extension sources. Install it before installing gevent:
RUN poetry add --dev cython
RUN poetry add gevent
The complete Dockerfile for reference, changes in bold:
FROM ubuntu:18.04
RUN apt-get update \
&& apt-get install -qyy -o APT::Install-Recommends=false -o APT::Install-Suggests=false \
file \
gcc \
python3 \
python3-dev \
python3-pip \
python3-setuptools \
python3-venv \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN pip3 install --cache-dir=/tmp/pipcache --upgrade pip && rm -rf /tmp/pipcache
RUN pip install --cache-dir=/tmp/pipcache poetry && rm -rf /tmp/pipcache
WORKDIR /src/app
RUN poetry new .
RUN apt update
RUN apt install -y make
RUN poetry add --dev wheel cython
RUN poetry add gevent
Neither wheel nor cython are required to actually run gevent, so they can be safely uninstalled afterwards to reduce the image size.

Docker: Failed building wheel for scipy

I'm trying for facerecogition from (https://github.com/jamct/facerec) on my raspberry pi 3. Therefore the by runs with the newest version of Raspbian Stretch.
I am running:
docker build -t facerec:latest .
But I get the following error:
ERROR: Failed building wheel for scipy
ERROR: Could not build wheels for scipy which use PEP 517 and cannot be installed directly
Here is a little bit more of the log:
creating build/temp.linux-armv7l-3.6/scipy/fft
creating build/temp.linux-armv7l-3.6/scipy/fft/_pocketfft
compile options: '-DPOCKETFFT_PTHREADS -I/root/.local/include/python3.6m -I/usr/local/include/python3.6m -I/tmp/pip-build-env-u7r4c8tr/overlay/lib/python3.6/site-packages/numpy/core/include -I/usr/local/include/python3.6m -c'
extra options: '-std=c++14 -fvisibility=hidden'
g++: scipy/fft/_pocketfft/pypocketfft.cxx
Running from scipy source directory.
/tmp/pip-build-env-u7r4c8tr/overlay/lib/python3.6/site-packages/numpy/distutils/system_info.py:572: UserWarning:
Atlas (http://math-atlas.sourceforge.net/) libraries not found.
Directories to search for the libraries can be specified in the
numpy/distutils/site.cfg file (section [atlas]) or by setting
the ATLAS environment variable.
self.calc_info()
/tmp/pip-build-env-u7r4c8tr/overlay/lib/python3.6/site-packages/numpy/distutils/system_info.py:664: UserWarning: Specified path /usr/include/python3.6m is invalid.
return self.get_paths(self.section, key)
scipy/fft/_pocketfft/pypocketfft.cxx:15:31: fatal error: pybind11/pybind11.h: No such file or directory
#include <pybind11/pybind11.h>
^
compilation terminated.
scipy/fft/_pocketfft/pypocketfft.cxx:15:31: fatal error: pybind11/pybind11.h: No such file or directory
#include <pybind11/pybind11.h>
^
compilation terminated.
error: Command "g++ -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DPOCKETFFT_PTHREADS -I/root/.local/include/python3.6m -I/usr/local/include/python3.6m -I/tmp/pip-build-env-u7r4c8tr/overlay/lib/python3.6/site-packages/numpy/core/include -I/usr/local/include/python3.6m -c scipy/fft/_pocketfft/pypocketfft.cxx -o build/temp.linux-armv7l-3.6/scipy/fft/_pocketfft/pypocketfft.o -MMD -MF build/temp.linux-armv7l-3.6/scipy/fft/_pocketfft/pypocketfft.o.d -std=c++14 -fvisibility=hidden" failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for scipy
ERROR: Could not build wheels for scipy which use PEP 517 and cannot be installed directly
The command '/bin/sh -c cd /face_recognition && pip3 install -r requirements.txt && python3 setup.py install' returned a non-zero code: 1
This is the dockerfile:
#Dockerfile for face-recognition
#Based on https://github.com/denverdino/face_recognition_pi
FROM resin/raspberry-pi-python:3
COPY pip.conf /root/.pip/pip.conf
RUN apt-get -y update
RUN apt-get install -y --fix-missing \
build-essential \
cmake \
gfortran \
git \
wget \
curl \
graphicsmagick \
libgraphicsmagick1-dev \
libatlas-dev \
libavcodec-dev \
libavformat-dev \
libboost-all-dev \
libgtk2.0-dev \
libjpeg-dev \
liblapack-dev \
libswscale-dev \
pkg-config \
python3-dev \
zip \
&& apt-get clean && rm -rf /tmp/* /var/tmp/*
RUN python3 -m ensurepip --upgrade && pip3 install --upgrade picamera[array] dlib
RUN pip install --upgrade pip
RUN pip install --upgrade pip setuptools wheel
RUN git clone --single-branch https://github.com/ageitgey/face_recognition.git
RUN cd /face_recognition && \
pip3 install -r requirements.txt && \
python3 setup.py install
CMD cd /face_recognition/examples && \
python3 recognize_faces_in_pictures.py
Would be happy if somebody has an idea what to do now.
Thanks!
You have to install Pybind11 before building SciPy:
python3 -m pip install pybind11

How to install Adafruit-GPIO library in Docker

I'm new to Docker, so there could be something I'm doing wrong. I'm trying to install Adafruit-GPIO in a container, but I keep getting this error and I'm not sure how to solve it. I'm building the file locally on a Windows 10 pc, using Powershell.
I'v made sure that the GCC is installed correctly and it is. I've been searching online for an answer and there isn't much to go on.
Dockerfile:
FROM balenalib/raspberry-pi-debian-python:3.7.2
RUN pip3 install --upgrade pip
RUN sudo pip3 install --upgrade setuptools
RUN sudo apt-get update && apt-get -y install gcc
RUN pip3 install adafruit-gpio
I'm expecting the file to compile and work successfully. Instead I'm getting this,
ERROR: Complete output from command /usr/local/bin/python3.7 -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-qfol0jyh/spidev/setup.py'"'"';f=getattr(tokenize, '"'"'open'"
'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-i37a5wvt/install-record.txt -
-single-version-externally-managed --compile:
ERROR: running install
running build
running build_ext
building 'spidev' extension
creating build
creating build/temp.linux-armv6l-3.7
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/usr/local/include/python3.7m -c spidev_module.c -o build/temp.linux-armv6l-3.7/spidev_module.o
In file included from /usr/lib/gcc/arm-linux-gnueabihf/6/include-fixed/syslimits.h:7:0,
from /usr/lib/gcc/arm-linux-gnueabihf/6/include-fixed/limits.h:34,
from /usr/local/include/python3.7m/Python.h:11,
from spidev_module.c:28:
/usr/lib/gcc/arm-linux-gnueabihf/6/include-fixed/limits.h:168:61: fatal error: limits.h: No such file or directory
#include_next <limits.h> /* recurse down to the real one */
^
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Command "/usr/local/bin/python3.7 -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-qfol0jyh/spidev/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);cod
e=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-i37a5wvt/install-record.txt --single-version-external
ly-managed --compile" failed with error code 1 in /tmp/pip-install-qfol0jyh/spidev/
Install build-essential to replace gcc could make you work, see official git.
In fact, when build some source code, always better to install build-essential because it will not only install gcc, but also some dev package. Your error fatal error: limits.h: No such file or directory just because miss these dev package.
In a word, next will works for you:
RUN sudo apt-get update && apt-get -y install build-essential

Error cannot find -lz building MariaDB on a debian based container

I'm trying to build MariaDB on a Debian based container. But it cannot find a z library.
Here is the container image script:
FROM debian
RUN apt-get update
RUN apt-get install -y libncurses-dev
RUN apt-get install -y build-essential;
RUN apt-get install -y cmake;
COPY mariadb-10.1.18.tar.gz /usr/bin/
WORKDIR /usr/bin/
RUN gzip -d mariadb-10.1.18.tar.gz
RUN tar -xvf mariadb-10.1.18.tar
RUN ln -s mariadb-10.1.18 mariadb
WORKDIR /usr/bin/mariadb/
RUN mkdir install; mkdir install/data; mkdir install/var; mkdir install/etc; mkdir install/tmp
RUN cd /usr/bin/mariadb/;
RUN rm -f CMakeCache.txt;
RUN cmake \
-DCMAKE_INSTALL_PREFIX=/usr/bin/mariadb/install \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/bin/mariadb/install/data \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/bin/mariadb/install/boost \
-DMYSQL_UNIX_ADDR=/usr/bin/mariadb/install/tmp/mariadb.sock
And the console output:
[ 77%] Building CXX object storage/tokudb/PerconaFT/ft/CMakeFiles/ft.dir/log_print.cc.o
Linking CXX shared library libft.so
/usr/bin/ld: cannot find -lz
collect2: error: ld returned 1 exit status
storage/tokudb/PerconaFT/ft/CMakeFiles/ft.dir/build.make:1323: recipe for target 'storage/tokudb/PerconaFT/ft/libft.so' failed
make[2]: *** [storage/tokudb/PerconaFT/ft/libft.so] Error 1
CMakeFiles/Makefile2:3438: recipe for target 'storage/tokudb/PerconaFT/ft/CMakeFiles/ft.dir/all' failed
make[1]: *** [storage/tokudb/PerconaFT/ft/CMakeFiles/ft.dir/all] Error 2
Makefile:147: recipe for target 'all' failed
make: *** [all] Error 2
The command '/bin/sh -c make' returned a non-zero code: 2
either change the container script and specify CMake parameter -DWITH_ZLIB=bundled to use zlib sources in extra/zlib or install zlib by apt-get install zlib-devel

Sudo make install permissions issue on Ubuntu 14.04

I have amended a script from https://github.com/jayrambhia/Install-OpenCV/blob/master/Ubuntu/2.4/opencv2_4_10.sh to try to install OpenCV 2.4.13 onto a vm running Ubuntu 14.04 where I have sudo permission. I'm new to openCV, cmake & make so any help getting this script to work would be appreciated as I have to install it on 20 vm's.
After a few minutes of running the script returns with an error saying can't
/bin/sh: 1: cd: can't cd to /home/myaccount/setups/OpenCV/opencv-2.4.13/build
and
make[2]: *** [3rdparty/libtiff/CMakeFiles/libtiff.dir/depend] Error 2
make[1]: *** [3rdparty/libtiff/CMakeFiles/libtiff.dir/all] Error 2
The last few lines of the output is included below and the script is before that.
Any ideas why the script wont complete successfully or how to correct the permissions issue?
Extra Details
I'm not sure if these are relevant but as I dig into the problem I'll update this section
cmake version 2.8
Makerfile mentions # The shell in which to execute make rules. SHELL
= /bin/sh but my terminal reports echo $0 as bash
when I run make install V=1 it builds 100% but then reports
-- Install configuration: "RELEASE" CMake Error at cmake_install.cmake:36 (FILE): file cannot create directory: /usr/local/include/opencv2. Maybe need administrative privileges
But when I run sudo make install V=1 I get can't cd error above
Adding Shebang #!/bin/bash to the start of my script didn't solve it
Running the script on a fresh ubuntu local machine alows the script to run but I need to get it running on the hosted vm
umask of setups folder (where script runs and creates a directory is 0022 . Permissions for setups folder is 755, group = Domain Users, Owner = myaccount Thats where the source files folder gets created as well as the build folder which is also 755 after it is created
Script
arch=$(uname -m)
if [ "$arch" == "i686" -o "$arch" == "i386" -o "$arch" == "i486" -o "$arch" == "i586" ]; then
flag=1
else
flag=0
fi
echo "Installing OpenCV 2.4.13"
mkdir OpenCV
cd OpenCV
echo "Removing any pre-installed ffmpeg and x264"
sudo apt-get -y remove ffmpeg x264 libx264-dev
echo "Installing unzip"
sudo apt-get -y install unzip
echo "Installing Dependenices"
sudo apt-get -y install libopencv-dev
sudo apt-get -y install build-essential checkinstall cmake pkg-config yasm
sudo apt-get -y install libtiff4-dev libjpeg-dev libjasper-dev
sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev
sudo apt-get -y install python-dev python-numpy
sudo apt-get -y install libtbb-dev libeigen3-dev
sudo apt-get -y install libqt4-dev libgtk2.0-dev
sudo apt-get -y install libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-core-dev
sudo apt-get -y install x264 v4l-utils ffmpeg
sudo apt-get -y install libgtk2.0-dev
echo "Downloading OpenCV 2.4.13"
if ! [ -f "OpenCV-2.4.13.zip" ]; then
wget -O OpenCV-2.4.13.zip http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.13/opencv-2.4.13.zip/download
fi
echo "Installing OpenCV 2.4.13"
if ! [ -d "opencv-2.4.13" ]; then
unzip OpenCV-2.4.13.zip
fi
rm OpenCV-2.4.13.zip
cd opencv-2.4.13
rm -rf build
mkdir build
cd build
cmake -D CUDA_ARCH_BIN=3.2 -D CUDA_ARCH_PTX=3.2 -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D BUILD_TIFF=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
make -j$(nproc)
sudo make install
sudo sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
echo "OpenCV 2.4.13 ready to be used"
Command Output
[100%] Build Java tests
Buildfile: /home/myaccount/setups/OpenCV/opencv-2.4.13/build/modules/java/test/.build/build.xml
build:
compile:
[mkdir] Created dir: /home/myaccount/setups/OpenCV/opencv-2.4.13/build/modules/java/test/.build/build/classes
[javac] Compiling 104 source files to /home/myaccount/setups/OpenCV/opencv-2.4.13/build/modules/java/test/.build/build/classes
jar:
[mkdir] Created dir: /home/myaccount/setups/OpenCV/opencv-2.4.13/build/modules/java/test/.build/build/jar
[jar] Building jar: /home/myaccount/setups/OpenCV/opencv-2.4.13/build/modules/java/test/.build/build/jar/opencv-test.jar
BUILD SUCCESSFUL
Total time: 6 seconds
[100%] Built target opencv_test_java
[sudo] password for myaccount:
Sorry, try again.
[sudo] password for myaccount:
/bin/sh: 1: cd: can't cd to /home/myaccount/setups/OpenCV/opencv-2.4.13/build
make[2]: *** [3rdparty/libtiff/CMakeFiles/libtiff.dir/depend] Error 2
make[1]: *** [3rdparty/libtiff/CMakeFiles/libtiff.dir/all] Error 2
make: *** [all] Error 2
OpenCV 2.4.13 ready to be used
myaccount#vm-20161023-002:~/setups$
What popped up into my head to explain the lack of permission problem: if your /home is on NFS, root may have nobody's permission on files there. There are quite a few related questions on StackExchange.
My solution would be not to try installing third-party software as root in the first place. Executing as root, your make install can do anything, including adding or overwriting files that are already managed by your software package manager. This may confuse the package manager or even render your system unusable. It's better to install the software somewhere else; /usr/local and /opt were created for this purpose. In order to make sure your installation procedure doesn't deviate from this, you can create a different user (which I call local), chown -R these directories to that user, and install using sudo -u local instead of sudoing to root. This will be fine for most installations, and should you run into one that tries to do something requiring root permissions (such as writing files to /etc or /usr/bin, restarting system services, doing tricky things with permissions, etc.), it will fail with an error message, allowing you to decide whether you want this before it has already happened. I have no idea whether OpenCV requires any such steps.

Resources