ERROR: No matching distribution found for cryptography==3.2.1

Viewed 5976

I'm trying to install cryptography==3.2.1 to my django project but I got this error

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

base image docker file content built with tag python3.10-alpine:base

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

my project 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 . .
1 Answers

You are missing the gcc compiler from the image. The reason the fist Dockerfile works is that, before the pip install was called, the build environment was set up.

Uncomment the environment preparation steps, change the order of the actions, to prepare the environment with the tools before you can install python libraries.

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

You might need to add additional binary libraries if you need them for your python library.

Related