[英]Problem building docker with numpy and pandas over arm64
I'm trying to build a docker image with docker-compose in my ARM64 rasperry pi but it seems to be imposible.我正在尝试在我的 ARM64 树莓派 pi 中使用 docker-compose 构建一个 docker 映像,但这似乎是不可能的。
This is my dockerfile:这是我的 dockerfile:
FROM python:3.6-slim
RUN apt-get update && apt-get -y install python3-dev
RUN apt-get -y install python3-numpy
RUN apt-get -y install python3-pandas
ENTRYPOINT ["python3", "app.py"]
It seems to be OK, but when app.py is run, it gives an error: "Module numpy not found", and the same for pandas module.看起来没问题,但是当 app.py 运行时,它给出了一个错误:“Module numpy not found”,对于 pandas 模块也是如此。
If I try to install numpy and pandas using pip:如果我尝试使用 pip 安装 numpy 和 pandas:
RUN pip install numpy pandas
It gives me an error or, more usually, the raspberry just gets frozen and I have to unplug it to recover.它给了我一个错误,或者更常见的是,树莓被冻结了,我必须拔掉它才能恢复。
I have tried with different versions of python for the source image and also using several ubuntu images and installing python.我已经尝试使用不同版本的 python 作为源图像,还使用了几个 ubuntu 图像并安装了 python。
Any idea of how can I install numpy and pandas in docker for my raspberry pi (ARM64)?知道如何在 docker 中为我的树莓派 (ARM64) 安装 numpy 和 pandas 吗?
Thanks谢谢
The problems seems to be with the python version. 问题似乎出在python版本上。 I'm using a python3.6 docker image but, both python3-numpy and python3-pandas packages require python3.5, so when those packages are installed a new version of python is also installed.
我正在使用python3.6 docker映像,但是python3-numpy和python3-pandas软件包都需要python3.5,因此,在安装这些软件包时,还会安装新版本的python。 This is why when I'm trying to import those modules the python interpreter can't found them, because they are installed for another python version.
这就是为什么当我尝试导入这些模块时,python解释器找不到它们的原因,因为它们是为另一个python版本安装的。
Finaly I solved it using a generic docker debian image and installing python3.5 myself instead of using a python docker image. 最后,我使用通用的docker debian映像并自己安装了python3.5来解决它,而不是使用python docker映像。
FROM debian:stretch-slim
RUN apt-get update && apt-get -y dist-upgrade
RUN apt-get -y install build-essential libssl-dev libffi-dev python3.5 libblas3 libc6 liblapack3 gcc python3-dev python3-pip cython3
RUN apt-get -y install python3-numpy python3-sklearn
RUN apt-get -y install python3-pandas
COPY requirements.txt /tmp/
RUN pip3 install -r /tmp/requirements.txt
This Dockerfile worked for me on the Raspberry Pi 3 B+ with Software-Version: Linux raspberrypi 5.10.63-v7+ (Consider updating it)这个 Dockerfile 在 Raspberry Pi 3 B+ 上对我有用,软件版本: Linux raspberrypi 5.10.63-v7+ (考虑更新它)
FROM python:3.9-buster
WORKDIR /
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
I am not sure, but I think it helped also to clean docker ie remove all images and containers with the following commands:我不确定,但我认为它也有助于清理 docker,即使用以下命令删除所有图像和容器:
Warning: This commands deletes all images and containers!警告:此命令会删除所有图像和容器!
$ docker container prune
$ docker image prune -a
Or reset Docker completely (deletes also volumes and networks):或者完全重置 Docker(同时删除卷和网络):
$ docker system prune --volumes
I recommend to create requirements.txt
file. 我建议创建
requirements.txt
文件。 Inside you can declare packets to install. 在里面可以声明要安装的数据包。
The `Dockerfile': `Dockerfile':
FROM python
COPY app.py /workdir/
COPY requirements.txt /workdir/
WORKDIR /workdir
RUN pip install --trusted-host pypi.python.org -r requirements.txt
CMD python app.py
edit 编辑
I create Dockerfile
which import pandas lib and then checking if it work: 我创建了导入pandas lib的
Dockerfile
,然后检查它是否有效:
cat Dockerfile
FROM python
COPY app.py /workdir/
WORKDIR /workdir
RUN python -m pip install pandas
CMD python app.py
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.