【问题标题】:`pip install cyrptography ` not able to install on python3.7-alpine docker`pip install cyrptography`无法安装在python3.7-alpine docker上
【发布时间】:2021-06-29 12:54:17
【问题描述】:

我正在尝试使用以下 dockerfile 为 alpine3.7 python 基础安装密码学。 但是,我收到这样的错误:

#7 17.27 Failed to build cryptography cffi
#7 17.37 Installing collected packages: pycparser, six, idna, cffi, asn1crypto, pymysql, cryptography
#7 17.68     Running setup.py install for cffi: started
#7 18.04     Running setup.py install for cffi: finished with status 'error'
#7 18.04     ERROR: Command errored out with exit status 1:
#7 18.04      command: /usr/local/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-twxf8fj_/cffi_1f087e9b9e8c4af8b4e6bf3deb3a5bf9/setup.py'"'"'; __file__='"'"'/tmp/pip-install-twxf8fj_/cffi_1f087e9b9e8c4af8b4e6bf3deb3a5bf9/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'"'"'))' install --record /tmp/pip-record-j8mkceyt/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.7m/cffi
#7 18.04          cwd: /tmp/pip-install-twxf8fj_/cffi_1f087e9b9e8c4af8b4e6bf3deb3a5bf9/
#7 18.04     Complete output (48 lines):
#7 18.04     unable to execute 'gcc': No such file or directory
#7 18.04     unable to execute 'gcc': No such file or directory

根据cryptography 文档,我正在安装所有必要的软件包,但它仍然给我同样的错误。 Dockerfile:

FROM python:3.7-alpine
WORKDIR  /project
RUN apk add --no-cache --virtual gcc musl-dev python3-dev libffi-dev openssl-dev cargo mariadb-dev
RUN pip install pymysql cryptography

谁能指出我做错了什么?

【问题讨论】:

  • 它似乎找不到 gcc 编译器,尽管它应该是由 apk 命令安装的。完整的日志说了什么?
  • 我看到的使用--no-cache --virtual 的示例始终运行需要同一RUN 命令上的包的构建。也许如果你尝试RUN apk add --no-cache --virtual gcc musl-dev python3-dev libffi-dev openssl-dev cargo mariadb-dev && pip install pymysql cryptography
  • @super 还是一样的错误...

标签: docker alpine


【解决方案1】:

-t, --virtual NAME 不是将所有包添加到“世界”,而是创建一个新的 具有列出的依赖项的虚拟包并添加 到“世界”;命令的动作很容易恢复 通过删除虚拟包

这意味着当您安装包时,这些包不会添加到全局包中。而且这种变化很容易恢复。因此,如果我需要 gcc 来编译程序,但一旦程序编译完成,我就不再需要 gcc。

我可以在一个虚拟包中安装 gcc 和其他所需的包,它的所有依赖项和所有东西都可以删除这个虚拟包名称。下面是一个示例用法:

apk add --virtual .dep gcc
apk del .dep

所以,对你来说,在apk add --no-cache --virtual gcc 中,gcc 被错误地视为虚拟包名,这意味着你实际上没有安装 gcc。

要解决这个问题,请尝试在所有包之前添加一个虚拟包名称作为下一个:

/ # apk add --no-cache --virtual .dep gcc
fetch https://mirrors.ustc.edu.cn/alpine/v3.14/main/x86_64/APKINDEX.tar.gz
fetch https://mirrors.ustc.edu.cn/alpine/v3.14/community/x86_64/APKINDEX.tar.gz
(1/12) Installing libgcc (10.3.1_git20210424-r2)
(2/12) Installing libstdc++ (10.3.1_git20210424-r2)
(3/12) Installing binutils (2.35.2-r2)
(4/12) Installing libgomp (10.3.1_git20210424-r2)
(5/12) Installing libatomic (10.3.1_git20210424-r2)
(6/12) Installing libgphobos (10.3.1_git20210424-r2)
(7/12) Installing gmp (6.2.1-r0)
(8/12) Installing isl22 (0.22-r0)
(9/12) Installing mpfr4 (4.1.0-r0)
(10/12) Installing mpc1 (1.2.1-r0)
(11/12) Installing gcc (10.3.1_git20210424-r2)
(12/12) Installing .dep (20210629.140945)
Executing busybox-1.33.1-r2.trigger
OK: 122 MiB in 47 packages
/ # gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-alpine-linux-musl/10.3.1/lto-wrapper
Target: x86_64-alpine-linux-musl
Configured with: /home/buildozer/aports/main/gcc/src/gcc-10.3.1_git20210424/configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --build=x86_64-alpine-linux-musl --host=x86_64-alpine-linux-musl --target=x86_64-alpine-linux-musl --with-pkgversion='Alpine 10.3.1_git20210424' --enable-checking=release --disable-fixed-point --disable-libstdcxx-pch --disable-multilib --disable-nls --disable-werror --disable-symvers --enable-__cxa_atexit --enable-default-pie --enable-default-ssp --enable-cloog-backend --enable-languages=c,c++,d,objc,go,fortran,ada --disable-libssp --disable-libmpx --disable-libmudflap --disable-libsanitizer --enable-shared --enable-threads --enable-tls --with-system-zlib --with-linker-hash-style=gnu
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.3.1 20210424 (Alpine 10.3.1_git20210424)

或者直接按照文档说的,去掉--virtual

apk add gcc

【讨论】:

  • 谢谢。只是删除 --virtual 帮助我构建了图像。这是新知识
猜你喜欢
  • 1970-01-01
  • 2018-07-13
  • 2020-10-17
  • 1970-01-01
  • 2019-02-23
  • 2020-01-07
  • 2016-01-30
  • 2016-11-28
  • 2018-09-23
相关资源
最近更新 更多