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

2024-09-28 19:32:55 发布

您现在位置:Python中文网/ 问答频道 /正文

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

由于此映像是为armv7体系结构构建的,因此直接安装numpy、scipy和pandas是一件痛苦的事情(它花费的时间太长,最终会中断)。所以我决定用Miniconda和树莓皮包装。这很好(安装可以在映像构建期间完成)

现在我正在尝试安装google软件包google-crc32c==1.1.2google-cloud-bigquery。有了pip,这是可能的,并且图像是正确构建的。但是,如果我使用此映像运行容器,它将始终重新启动,并显示以下错误日志:

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

我想我必须安装带有conda的google软件包,但是没有适用于armv7体系结构的软件包:

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

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

是否有可能使用Miniconda for 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"]

Tags: installpiprunpynumpycloudpandaslinux
1条回答
网友
1楼 · 发布于 2024-09-28 19:32:55

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

但是,我可以直接从piwheels用轮子安装它们。 因此,我不得不在“/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(如推荐的here)来实现这一点

{}的内容:

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

相关问题 更多 >