【问题标题】:ERROR: No matching distribution found for cryptography==3.2.1错误:未找到密码学的匹配分布==3.2.1
【发布时间】:2021-03-14 11:29:51
【问题描述】:

我正在尝试将 cryptography==3.2.1 安装到我的 django 项目中,但出现此错误

Collecting cryptography==3.2.1
  Downloading cryptography-3.2.1.tar.gz (540 kB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'error'
  ERROR: Command errored out with exit status 1:
   command: /usr/local/bin/python /usr/local/lib/python3.10/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-5acxrfz0/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=40.6.0' wheel 'cffi>=1.8,!=1.11.3; platform_python_implementation != '"'"'PyPy'"'"''
       cwd: None
  Complete output (122 lines):
  Collecting setuptools>=40.6.0
    Downloading setuptools-54.1.1-py3-none-any.whl (784 kB)
  Collecting wheel
    Downloading wheel-0.36.2-py2.py3-none-any.whl (35 kB)
  Collecting cffi!=1.11.3,>=1.8
    Downloading cffi-1.14.5.tar.gz (475 kB)
  Collecting pycparser
    Downloading pycparser-2.20-py2.py3-none-any.whl (112 kB)
  Building wheels for collected packages: cffi
    Building wheel for cffi (setup.py): started
    Building wheel for cffi (setup.py): finished with status 'error'
    ERROR: Command errored out with exit status 1:
     command: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-p5wjmnwg/cffi_4138eef598d743ef92d64bbc9e0b8ac5/setup.py'"'"'; __file__='"'"'/tmp/pip-install-p5wjmnwg/cffi_4138eef598d743ef92d64bbc9e0b8ac5/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-h86bujlk
         cwd: /tmp/pip-install-p5wjmnwg/cffi_4138eef598d743ef92d64bbc9e0b8ac5/
    Complete output (47 lines):
  
        No working compiler found, or bogus compiler options passed to
        the compiler from Python's standard "distutils" module.  See
        the error messages above.  Likely, the problem is not related
        to CFFI but generic to the setup.py of any Python package that
        tries to compile C code.  (Hints: on OS/X 10.8, for errors about
        -mno-fused-madd see http://stackoverflow.com/questions/22313407/
        Otherwise, see https://wiki.python.org/moin/CompLangPython or
        the IRC channel #python on irc.freenode.net.)
  
        Trying to continue anyway.  If you are trying to install CFFI from
        a build done in a different context, you can ignore this warning.
  
    running bdist_wheel
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.10
    creating build/lib.linux-x86_64-3.10/cffi
    copying cffi/api.py -> build/lib.linux-x86_64-3.10/cffi
    copying cffi/vengine_cpy.py -> build/lib.linux-x86_64-3.10/cffi
    copying cffi/cffi_opcode.py -> build/lib.linux-x86_64-3.10/cffi
    copying cffi/backend_ctypes.py -> build/lib.linux-x86_64-3.10/cffi
    copying cffi/setuptools_ext.py -> build/lib.linux-x86_64-3.10/cffi
    copying cffi/ffiplatform.py -> build/lib.linux-x86_64-3.10/cffi
    copying cffi/cparser.py -> build/lib.linux-x86_64-3.10/cffi
    copying cffi/verifier.py -> build/lib.linux-x86_64-3.10/cffi
    copying cffi/vengine_gen.py -> build/lib.linux-x86_64-3.10/cffi
    copying cffi/lock.py -> build/lib.linux-x86_64-3.10/cffi
    copying cffi/commontypes.py -> build/lib.linux-x86_64-3.10/cffi
    copying cffi/model.py -> build/lib.linux-x86_64-3.10/cffi
    copying cffi/error.py -> build/lib.linux-x86_64-3.10/cffi
    copying cffi/recompiler.py -> build/lib.linux-x86_64-3.10/cffi
    copying cffi/pkgconfig.py -> build/lib.linux-x86_64-3.10/cffi
    copying cffi/__init__.py -> build/lib.linux-x86_64-3.10/cffi
    copying cffi/_cffi_include.h -> build/lib.linux-x86_64-3.10/cffi
    copying cffi/parse_c_type.h -> build/lib.linux-x86_64-3.10/cffi
    copying cffi/_embedding.h -> build/lib.linux-x86_64-3.10/cffi
    copying cffi/_cffi_errors.h -> build/lib.linux-x86_64-3.10/cffi
    warning: build_py: byte-compiling is disabled, skipping.
  
    running build_ext
    building '_cffi_backend' extension
    creating build/temp.linux-x86_64-3.10
    creating build/temp.linux-x86_64-3.10/c
    gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/usr/include/ffi -I/usr/include/libffi -I/usr/local/include/python3.10 -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.10/c/_cffi_backend.o
    error: command 'gcc' failed: No such file or directory
    ----------------------------------------
    ERROR: Failed building wheel for cffi
    Running setup.py clean for cffi
  Failed to build cffi
  Installing collected packages: pycparser, wheel, setuptools, cffi
      Running setup.py install for cffi: started
      Running setup.py install for cffi: finished with status 'error'
      ERROR: Command errored out with exit status 1:
       command: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-p5wjmnwg/cffi_4138eef598d743ef92d64bbc9e0b8ac5/setup.py'"'"'; __file__='"'"'/tmp/pip-install-p5wjmnwg/cffi_4138eef598d743ef92d64bbc9e0b8ac5/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-sx_wm_b2/install-record.txt --single-version-externally-managed --prefix /tmp/pip-build-env-5acxrfz0/overlay --compile --install-headers /tmp/pip-build-env-5acxrfz0/overlay/include/python3.10/cffi
           cwd: /tmp/pip-install-p5wjmnwg/cffi_4138eef598d743ef92d64bbc9e0b8ac5/
      Complete output (47 lines):
  
          No working compiler found, or bogus compiler options passed to
          the compiler from Python's standard "distutils" module.  See
          the error messages above.  Likely, the problem is not related
          to CFFI but generic to the setup.py of any Python package that
          tries to compile C code.  (Hints: on OS/X 10.8, for errors about
          -mno-fused-madd see http://stackoverflow.com/questions/22313407/
          Otherwise, see https://wiki.python.org/moin/CompLangPython or
          the IRC channel #python on irc.freenode.net.)
  
          Trying to continue anyway.  If you are trying to install CFFI from
          a build done in a different context, you can ignore this warning.
  
      running install
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-3.10
      creating build/lib.linux-x86_64-3.10/cffi
      copying cffi/api.py -> build/lib.linux-x86_64-3.10/cffi
      copying cffi/vengine_cpy.py -> build/lib.linux-x86_64-3.10/cffi
      copying cffi/cffi_opcode.py -> build/lib.linux-x86_64-3.10/cffi
      copying cffi/backend_ctypes.py -> build/lib.linux-x86_64-3.10/cffi
      copying cffi/setuptools_ext.py -> build/lib.linux-x86_64-3.10/cffi
      copying cffi/ffiplatform.py -> build/lib.linux-x86_64-3.10/cffi
      copying cffi/cparser.py -> build/lib.linux-x86_64-3.10/cffi
      copying cffi/verifier.py -> build/lib.linux-x86_64-3.10/cffi
      copying cffi/vengine_gen.py -> build/lib.linux-x86_64-3.10/cffi
      copying cffi/lock.py -> build/lib.linux-x86_64-3.10/cffi
      copying cffi/commontypes.py -> build/lib.linux-x86_64-3.10/cffi
      copying cffi/model.py -> build/lib.linux-x86_64-3.10/cffi
      copying cffi/error.py -> build/lib.linux-x86_64-3.10/cffi
      copying cffi/recompiler.py -> build/lib.linux-x86_64-3.10/cffi
      copying cffi/pkgconfig.py -> build/lib.linux-x86_64-3.10/cffi
      copying cffi/__init__.py -> build/lib.linux-x86_64-3.10/cffi
      copying cffi/_cffi_include.h -> build/lib.linux-x86_64-3.10/cffi
      copying cffi/parse_c_type.h -> build/lib.linux-x86_64-3.10/cffi
      copying cffi/_embedding.h -> build/lib.linux-x86_64-3.10/cffi
      copying cffi/_cffi_errors.h -> build/lib.linux-x86_64-3.10/cffi
      warning: build_py: byte-compiling is disabled, skipping.
  
      running build_ext
      building '_cffi_backend' extension
      creating build/temp.linux-x86_64-3.10
      creating build/temp.linux-x86_64-3.10/c
      gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/usr/include/ffi -I/usr/include/libffi -I/usr/local/include/python3.10 -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.10/c/_cffi_backend.o
      error: command 'gcc' failed: No such file or directory
      ----------------------------------------
  ERROR: Command errored out with exit status 1: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-p5wjmnwg/cffi_4138eef598d743ef92d64bbc9e0b8ac5/setup.py'"'"'; __file__='"'"'/tmp/pip-install-p5wjmnwg/cffi_4138eef598d743ef92d64bbc9e0b8ac5/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-sx_wm_b2/install-record.txt --single-version-externally-managed --prefix /tmp/pip-build-env-5acxrfz0/overlay --compile --install-headers /tmp/pip-build-env-5acxrfz0/overlay/include/python3.10/cffi Check the logs for full command output.
  ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/94/5c/42de91c7fbdb817b2d9a4e64b067946eb38a4eb36c1a09c96c87a0f86a82/cryptography-3.2.1.tar.gz#sha256=d3d5e10be0cf2a12214ddee45c6bd203dab435e3d83b4560c03066eda600bfe3 (from https://pypi.org/simple/cryptography/) (requires-python:>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*). Command errored out with exit status 1: /usr/local/bin/python /usr/local/lib/python3.10/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-5acxrfz0/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=40.6.0' wheel 'cffi>=1.8,!=1.11.3; platform_python_implementation != '"'"'PyPy'"'"'' Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement cryptography==3.2.1
ERROR: No matching distribution found for cryptography==3.2.1
ERROR: Service 'web' failed to build : The command '/bin/sh -c pip install --upgrade pip     && pip install -r requirements.txt     && chmod +x docker-entrypoint.sh' returned a non-zero code: 1

使用标签python3.10-alpine:base构建的基础镜像docker文件内容

FROM python:3.10.0a6-alpine3.13
ENV PYTHONUNBUFFERED 1
RUN apk add --no-cache --virtual .build-deps \
    ca-certificates gcc postgresql-dev linux-headers musl-dev openssl-dev cargo  ffmpeg \
    libffi-dev jpeg-dev zlib-dev python3-dev    py3-cryptography \
#    && pip install psycopg2==2.8.1 Pillow==6.0.0 \
    && find /usr/local \
        \( -type d -a -name test -o -name tests \) \
        -o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
        -exec rm -rf '{}' + \
    && runDeps="$( \
        scanelf --needed --nobanner --recursive /usr/local \
                | awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
                | sort -u \
                | xargs -r apk info --installed \
                | sort -u \
    )" \
    && apk add --virtual .rundeps $runDeps \
    && apk del .build-deps

我的项目 Dockerfile

FROM python3.10-alpine:base

# set work directory
ENV APP_PATH /usr/src/src/
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

WORKDIR $APP_PATH



## install dependencies
#COPY ./src .

# py-cryptography is required
COPY requirements.txt docker-entrypoint.sh $APP_PATH

RUN pip install --upgrade pip \
    && pip install -r requirements.txt \
    && chmod +x docker-entrypoint.sh
# RUN apt update \
#    && apk add gcc musl-dev python3-dev libffi-dev openssl-dev cargo jpeg-dev zlib-dev  ffmpeg \
#    && pip install --upgrade pip \
#    && pip install -r requirements.txt \
#    && chmod +x docker-entrypoint.sh

# copy project
COPY . .

【问题讨论】:

  • 看来您正在使用 Python 3.10 并且 cffi 包还没有为该版本的 Python 预构建二进制轮,所以 pip 下载了源代码压缩包,尝试编译它,然后失败了由于目标系统上缺少gcc(C 编译器),如错误消息中明确指出的那样。

标签: python docker pip cryptography alpine


【解决方案1】:

图片中缺少gcc 编译器。第一个Dockerfile起作用的原因是,在调用pip install之前,构建环境已经建立。

取消注释环境准备步骤,更改操作顺序,使用工具准备环境,然后才能安装python库。

RUN apt update \
    && apk add alpine-sdk gcc musl-dev python3-dev libffi-dev openssl-dev cargo jpeg-dev zlib-dev  ffmpeg

RUN pip install --upgrade pip \
    && pip install -r requirements.txt \
    && chmod +x docker-entrypoint.sh

如果您的 python 库需要额外的二进制库,您可能需要添加它们。

【讨论】:

  • - 在基础镜像中我已经安装了gcc,为什么要在我的项目镜像中重新安装这些包?
  • 有些包是用其他语言实现的,通常是C/C++。要安装此类软件包,您需要具有该语言的开发环境。在您的情况下,您需要 C/C++ 构建环境才能编译和安装软件包。我已经添加了我之前忘记的alpine-sdk,这是添加额外的工具。 libffi, jpg, ... 包的其余部分取自您的示例,如果您不需要它们,请不要添加它们。
  • 有同样的错误信息,对我来说添加 apk update && apk add alpine-sdk gcc musl-dev python3-dev libffi-dev openssl-dev 有效,谢谢!
猜你喜欢
  • 1970-01-01
  • 2020-06-13
  • 1970-01-01
  • 1970-01-01
  • 2020-09-19
  • 2020-10-07
  • 1970-01-01
  • 2017-05-05
  • 2021-10-19
相关资源
最近更新 更多