Docker 镜像构建:如何为 armv7 架构安装 python 包 google-cloud-bigquery 和 numpy、scipy 和 pandas (Miniconda3)?

奥海蒙多

我试图建立它应该运行python脚本,需要一个码头工人形象numpyscipypandasgoogle-cloud-bigquery

由于此映像是为armv7架构构建的,因此直接安装 numpy、scipy 和 pandas 是一件很痛苦的事情(花费的时间太长,最后它会崩溃)。所以我决定使用 Miniconda 并使用树莓派的包。效果很好(安装可以在映像构建期间完成)。

现在我正在尝试安装 google 软件包google-crc32c==1.1.2google-cloud-bigquery. 使用 pip 这是可能的,并且图像构建正确。但是如果我用这个 Image 运行一个容器,它总是重新启动并给我这个错误日志:

File "/usr/src/app/bigquery.py", line 1, in <module>
    from google.cloud import bigquery
ImportError: No module named 'google'

我想我必须安装 google 包,conda但没有armv7可用架构

google-cloud-bigqueryAnaconda.org 上的软件包:https ://anaconda.org/search ? q = google+bigquery

google-crc32cAnaconda.org 上的软件包:https ://anaconda.org/search ? q = google-crc32c

是否有可能使用 Miniconda 为 armv7 架构安装那些 google 软件包?或者是否有另一种方法可以在不使用 miniconda 的情况下安装 numpy、scipy 和 pandas(但不直接安装它们)?

感谢您的任何帮助!

Dockerfile:

FROM python:3.7-buster

WORKDIR /usr/src/app

ENV PATH="/root/miniconda3/bin:${PATH}"
ARG PATH="/root/miniconda3/bin:${PATH}"

COPY main_prog.py bigquery.py requirements.txt ./

RUN wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-armv7l.sh
RUN mkdir /root/.conda
RUN /bin/bash Miniconda3-latest-Linux-armv7l.sh -b
RUN rm -f Miniconda3-latest-Linux-armv7l.sh \
    && echo "Running $(conda --version)"

RUN wget https://github.com/jjhelmus/berryconda/releases/download/v2.0.0/Berryconda3-2.0.0-Linux-armv7l.sh
RUN chmod +x Berryconda3-2.0.0-Linux-armv7l.sh ./Berryconda3-2.0.0-Linux-armv7l.sh
   
RUN conda list \
    && conda config --add channels rpi \
    && conda install python=3.6 -y\
    && conda install openblas blas -y\
    && conda install numpy -y\
    && conda install pandas -y\
    && conda install scipy -y

RUN pip install --upgrade pip

RUN pip install "google-crc32c==1.1.2"
RUN pip install google-cloud-bigquery

CMD ["python", "main_prog.py"]
奥海蒙多

我找不到使用 Miniconda 安装所有软件包的方法。

但是我可以直接用piwheels 的轮子安装它们因此,我不得不pip.conf在“/etc”目录中添加一个文件。

内容pip.conf

[global]
extra-index-url=https://www.piwheels.org/simple

此外,我必须安装libatlas-base-dev. 我只能通过在“/etc/apt/”目录中的“sources.list”中添加一个 URL deb http://ftp.de.debian.org/debian buster main(就像这里推荐的那样)来做到这一点

内容sources.list

# deb http://snapshot.debian.org/archive/debian/20210902T000000Z buster main
deb http://deb.debian.org/debian buster main
# deb http://snapshot.debian.org/archive/debian-security/20210902T000000Z buster/updates main
deb http://security.debian.org/debian-security buster/updates main
# deb http://snapshot.debian.org/archive/debian/20210902T000000Z buster-updates main
deb http://deb.debian.org/debian buster-updates main
deb http://ftp.de.debian.org/debian buster main

Dockerfile:

FROM python:3.7-buster

WORKDIR /usr/src/app

COPY main_prog.py bigquery.py requirements.txt pip.conf sources.list ./

RUN mv ./pip.conf /etc \
    && export PIP_CONFIG_FILE=/etc/pip.conf

RUN mv ./sources.list /etc/apt/

RUN apt-get update \
    && apt-get upgrade -y

RUN apt-get install libatlas-base-dev -y
RUN pip3 install --upgrade pip

RUN pip3 install numpy \
    && pip3 install scipy \
    && pip3 install pandas \
    && pip3 install google-crc32c \
    && pip3 install google-cloud-bigquery

CMD ["python", "main_prog.py"]

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章