问题背景:
为了将face_recognition
项目进行迁移,我们使用docker
对其进行镜像打包,使用的DockerFile
文件如下:
# Start FROM Nvidia PyTorch image https://ngc.nvidia.com/catalog/containers/nvidia:pytorch
FROM registry.baidubce.com/ais-public/ais2.3:cuda10.1_cudnn7-ubuntu16.04-py37
ENV PATH=/home/bml/anaconda3/envs/py3.7.4/bin:${PATH}
# 安装依赖软件
RUN apt-get update -y && \
apt-get install -y git cmake libsm6 libxext6 libxrender-dev
RUN python -m pip install --upgrade pip && \
pip install scikit-build
# 安装编译
RUN apt-get install -y software-properties-common && \
add-apt-repository ppa:ubuntu-toolchain-r/test && \
apt-get update -y && \
apt-get install -y gcc-6 g++-6 && \
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 50 && \
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 50
# Create working directory
RUN mkdir -p /home/dlib_face_recognition
WORKDIR /home/dlib_face_recognition
# Copy contents
COPY . /home/dlib_face_recognition/
#安装dlib
# RUN git clone -b 'v19.7' --single-branch https://github.com/davisking/dlib.git && \
RUN pip install --index-url https://mirrors.ustc.edu.cn/pypi/web/simple --requirement requirements.txt && \
mkdir -p /home/dlib_face_recognition/dlib-master/build && \
cmake -H/home/dlib_face_recognition/dlib-master -B/home/dlib_face_recognition/dlib-master/build -DDLIB_USE_CUDA=1 -DUSE_AVX_INSTRUCTIONS=1 && \
cmake --build /home/dlib_face_recognition/dlib-master/build && \
cd /home/dlib_face_recognition/dlib-master && \
python /home/dlib_face_recognition/dlib-master/setup.py install
CMD ["python","app.py"]
在构建过程中出现以下错误:
ERROR: Command errored out with exit status 1:
command: /home/bml/anaconda3/envs/py3.7.4/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-p8j36mb6/cryptography_932a41c98c9e47cb83ae52a12653f21b/setup.py'"'"'; __file__='"'"'/tmp/pip-install-p8j36mb6/cryptography_932a41c98c9e47cb83ae52a12653f21b/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-2yv7tziu
cwd: /tmp/pip-install-p8j36mb6/cryptography_932a41c98c9e47cb83ae52a12653f21b/
Complete output (116 lines):
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.7
creating build/lib.linux-x86_64-3.7/cryptography
copying src/cryptography/__about__.py -> build/lib.linux-x86_64-3.7/cryptography
copying src/cryptography/__init__.py -> build/lib.linux-x86_64-3.7/cryptography
copying src/cryptography/exceptions.py -> build/lib.linux-x86_64-3.7/cryptography
copying src/cryptography/fernet.py -> build/lib.linux-x86_64-3.7/cryptography
copying src/cryptography/utils.py -> build/lib.linux-x86_64-3.7/cryptography
creating build/lib.linux-x86_64-3.7/cryptography/hazmat
copying src/cryptography/hazmat/__init__.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat
creating build/lib.linux-x86_64-3.7/cryptography/x509
copying src/cryptography/x509/__init__.py -> build/lib.linux-x86_64-3.7/cryptography/x509
copying src/cryptography/x509/base.py -> build/lib.linux-x86_64-3.7/cryptography/x509
copying src/cryptography/x509/extensions.py -> build/lib.linux-x86_64-3.7/cryptography/x509
copying src/cryptography/x509/general_name.py -> build/lib.linux-x86_64-3.7/cryptography/x509
copying src/cryptography/x509/name.py -> build/lib.linux-x86_64-3.7/cryptography/x509
copying src/cryptography/x509/oid.py -> build/lib.linux-x86_64-3.7/cryptography/x509
creating build/lib.linux-x86_64-3.7/cryptography/hazmat/backends
copying src/cryptography/hazmat/backends/__init__.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/backends
copying src/cryptography/hazmat/backends/interfaces.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/backends
copying src/cryptography/hazmat/backends/multibackend.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/backends
creating build/lib.linux-x86_64-3.7/cryptography/hazmat/bindings
copying src/cryptography/hazmat/bindings/__init__.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/bindings
creating build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives
copying src/cryptography/hazmat/primitives/__init__.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives
copying src/cryptography/hazmat/primitives/cmac.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives
copying src/cryptography/hazmat/primitives/constant_time.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives
copying src/cryptography/hazmat/primitives/hashes.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives
copying src/cryptography/hazmat/primitives/hmac.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives
copying src/cryptography/hazmat/primitives/keywrap.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives
copying src/cryptography/hazmat/primitives/padding.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives
copying src/cryptography/hazmat/primitives/serialization.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives
creating build/lib.linux-x86_64-3.7/cryptography/hazmat/backends/commoncrypto
copying src/cryptography/hazmat/backends/commoncrypto/__init__.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/backends/commoncrypto
copying src/cryptography/hazmat/backends/commoncrypto/backend.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/backends/commoncrypto
copying src/cryptography/hazmat/backends/commoncrypto/ciphers.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/backends/commoncrypto
copying src/cryptography/hazmat/backends/commoncrypto/hashes.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/backends/commoncrypto
copying src/cryptography/hazmat/backends/commoncrypto/hmac.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/backends/commoncrypto
creating build/lib.linux-x86_64-3.7/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/__init__.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/backend.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/ciphers.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/cmac.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/decode_asn1.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/dh.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/dsa.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/ec.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/encode_asn1.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/hashes.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/hmac.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/rsa.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/utils.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/backends/openssl
copying src/cryptography/hazmat/backends/openssl/x509.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/backends/openssl
creating build/lib.linux-x86_64-3.7/cryptography/hazmat/bindings/commoncrypto
copying src/cryptography/hazmat/bindings/commoncrypto/__init__.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/bindings/commoncrypto
copying src/cryptography/hazmat/bindings/commoncrypto/binding.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/bindings/commoncrypto
creating build/lib.linux-x86_64-3.7/cryptography/hazmat/bindings/openssl
copying src/cryptography/hazmat/bindings/openssl/__init__.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/bindings/openssl
copying src/cryptography/hazmat/bindings/openssl/_conditional.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/bindings/openssl
copying src/cryptography/hazmat/bindings/openssl/binding.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/bindings/openssl
creating build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/asymmetric
copying src/cryptography/hazmat/primitives/asymmetric/__init__.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/asymmetric
copying src/cryptography/hazmat/primitives/asymmetric/dh.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/asymmetric
copying src/cryptography/hazmat/primitives/asymmetric/dsa.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/asymmetric
copying src/cryptography/hazmat/primitives/asymmetric/ec.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/asymmetric
copying src/cryptography/hazmat/primitives/asymmetric/padding.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/asymmetric
copying src/cryptography/hazmat/primitives/asymmetric/rsa.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/asymmetric
copying src/cryptography/hazmat/primitives/asymmetric/utils.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/asymmetric
creating build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/ciphers
copying src/cryptography/hazmat/primitives/ciphers/__init__.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/ciphers
copying src/cryptography/hazmat/primitives/ciphers/algorithms.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/ciphers
copying src/cryptography/hazmat/primitives/ciphers/base.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/ciphers
copying src/cryptography/hazmat/primitives/ciphers/modes.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/ciphers
creating build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/interfaces
copying src/cryptography/hazmat/primitives/interfaces/__init__.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/interfaces
creating build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/kdf
copying src/cryptography/hazmat/primitives/kdf/__init__.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/kdf
copying src/cryptography/hazmat/primitives/kdf/concatkdf.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/kdf
copying src/cryptography/hazmat/primitives/kdf/hkdf.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/kdf
copying src/cryptography/hazmat/primitives/kdf/kbkdf.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/kdf
copying src/cryptography/hazmat/primitives/kdf/pbkdf2.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/kdf
copying src/cryptography/hazmat/primitives/kdf/scrypt.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/kdf
copying src/cryptography/hazmat/primitives/kdf/x963kdf.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/kdf
creating build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/twofactor
copying src/cryptography/hazmat/primitives/twofactor/__init__.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/twofactor
copying src/cryptography/hazmat/primitives/twofactor/hotp.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/twofactor
copying src/cryptography/hazmat/primitives/twofactor/totp.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/twofactor
copying src/cryptography/hazmat/primitives/twofactor/utils.py -> build/lib.linux-x86_64-3.7/cryptography/hazmat/primitives/twofactor
running egg_info
writing src/cryptography.egg-info/PKG-INFO
writing dependency_links to src/cryptography.egg-info/dependency_links.txt
writing entry points to src/cryptography.egg-info/entry_points.txt
writing requirements to src/cryptography.egg-info/requires.txt
writing top-level names to src/cryptography.egg-info/top_level.txt
reading manifest file 'src/cryptography.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
no previously-included directories found matching 'docs/_build'
warning: no previously-included files matching '*' found under directory 'vectors'
writing manifest file 'src/cryptography.egg-info/SOURCES.txt'
running build_ext
generating cffi module 'build/temp.linux-x86_64-3.7/_padding.c'
creating build/temp.linux-x86_64-3.7
generating cffi module 'build/temp.linux-x86_64-3.7/_constant_time.c'
generating cffi module 'build/temp.linux-x86_64-3.7/_openssl.c'
building '_openssl' extension
creating build/temp.linux-x86_64-3.7/build
creating build/temp.linux-x86_64-3.7/build/temp.linux-x86_64-3.7
gcc -pthread -B /home/bml/anaconda3/envs/py3.7.4/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/bml/anaconda3/envs/py3.7.4/include/python3.7m -c build/temp.linux-x86_64-3.7/_openssl.c -o build/temp.linux-x86_64-3.7/build/temp.linux-x86_64-3.7/_openssl.o
build/temp.linux-x86_64-3.7/_openssl.c:570:30: fatal error: openssl/opensslv.h: No such file or directory
#include <openssl/opensslv.h>
^
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for cryptography
从报错信息中可以看出,主要错误如下:
build/temp.linux-x86_64-3.7/_openssl.c:570:30: fatal error: openssl/opensslv.h: No such file or directory
#include <openssl/opensslv.h>
^
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for cryptography
可能缺少openssl
,在ubuntu
系统中,安装libssl-dev
:
# Start FROM Nvidia PyTorch image https://ngc.nvidia.com/catalog/containers/nvidia:pytorch
FROM registry.baidubce.com/ais-public/ais2.3:cuda10.1_cudnn7-ubuntu16.04-py37
ENV PATH=/home/bml/anaconda3/envs/py3.7.4/bin:${PATH}
# 安装依赖软件
RUN apt-get update -y && \
apt-get install -y git cmake libsm6 libxext6 libxrender-dev libssl-dev
RUN python -m pip install --upgrade pip && \
pip install scikit-build
# 安装编译
RUN apt-get install -y software-properties-common && \
add-apt-repository ppa:ubuntu-toolchain-r/test && \
apt-get update -y && \
apt-get install -y gcc-6 g++-6 && \
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 50 && \
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 50
# Create working directory
RUN mkdir -p /home/dlib_face_recognition
WORKDIR /home/dlib_face_recognition
# Copy contents
COPY . /home/dlib_face_recognition/
#安装dlib
# RUN git clone -b 'v19.7' --single-branch https://github.com/davisking/dlib.git && \
RUN pip install --index-url https://mirrors.ustc.edu.cn/pypi/web/simple --requirement requirements.txt && \
mkdir -p /home/dlib_face_recognition/dlib-master/build && \
cmake -H/home/dlib_face_recognition/dlib-master -B/home/dlib_face_recognition/dlib-master/build -DDLIB_USE_CUDA=1 -DUSE_AVX_INSTRUCTIONS=1 && \
cmake --build /home/dlib_face_recognition/dlib-master/build && \
cd /home/dlib_face_recognition/dlib-master && \
python /home/dlib_face_recognition/dlib-master/setup.py install
CMD ["python","app.py"]
最终构建成功