【问题标题】:Docker image build: How to install python packages google-cloud-bigquery and numpy, scipy and pandas (Miniconda3) for an armv7 architecture?Docker 映像构建:如何为 armv7 架构安装 python 包 google-cloud-bigquery 和 numpy、scipy 和 pandas (Miniconda3)?
【发布时间】:2021-11-14 18:55:02
【问题描述】:

我正在尝试构建一个应该运行 python 脚本的 Docker 映像,该脚本需要 numpyscipypandasgoogle-cloud-bigquery

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

现在我正在尝试安装 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'

我想我必须使用 conda 安装 google 软件包,但没有适用于 armv7 架构的软件包:

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

google-crc32c Anaconda.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"]

【问题讨论】:

  • 你看过这个question with similar issue。不一样的架构,但也许有些想法会奏效。
  • 是的,我见过这个,但不幸的是,这对我没有帮助。我可以从link 安装带有轮子的软件包。所以我不再用 Miniconda 安装它们了。

标签: python google-bigquery dockerfile miniconda armv7


【解决方案1】:

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

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

pip.conf的内容:

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

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

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"]

【讨论】:

    猜你喜欢
    • 2019-04-10
    • 1970-01-01
    • 2017-03-26
    • 2022-01-21
    • 2014-10-07
    • 1970-01-01
    • 2014-06-03
    • 2011-11-21
    • 1970-01-01
    相关资源
    最近更新 更多