gpt4 book ai didi

Docker 为 numpy 构建,pandas 给出错误

转载 作者:行者123 更新时间:2023-12-02 06:51:28 25 4
gpt4 key购买 nike

我在名为 docker_test 的目录中有一个 Dockerfile。 docker_test的结构如下:

M00618927A:docker_test i854319$ ls 
Dockerfile hello_world.py

我的 dockerfile 如下所示:

  ### Dockerfile 

# Created by Baktaawar

# Pulling from base Python image

FROM python:3.6.7-alpine3.6

# author of file
LABEL maintainer="Baktawar"

# Set the working directory of the docker image
WORKDIR /docker_test
COPY . /docker_test


# packages that we need

RUN pip --no-cache-dir install numpy pandas jupyter


EXPOSE 8888

ENTRYPOINT ["python"]

CMD ["hello_world.py"]

我运行命令

docker build -t dockerfile . 

它开始构建过程,但随后出现以下错误,无法在图像中安装 numpy 等

Sending build context to Docker daemon  4.096kB
Step 1/8 : FROM python:3.6.7-alpine3.6
---> 8f30079779ef
Step 2/8 : LABEL maintainer="Baktawar"
---> Running in 7cf081021b1e
Removing intermediate container 7cf081021b1e
---> 581cf24fa4e6
Step 3/8 : WORKDIR /docker_test
---> Running in 7c58855c4332
Removing intermediate container 7c58855c4332
---> dae70a34626b
Step 4/8 : COPY . /docker_test
---> 432b174b4869
Step 5/8 : RUN pip --no-cache-dir install numpy pandas jupyter
---> Running in 972efa9336ed
Collecting numpy
Downloading https://files.pythonhosted.org/packages/cf/8d/6345b4f32b37945fedc1e027e83970005fc9c699068d2f566b82826515f2/numpy-1.16.2.zip (5.1MB)
Collecting pandas
Downloading https://files.pythonhosted.org/packages/81/fd/b1f17f7dc914047cd1df9d6813b944ee446973baafe8106e4458bfb68884/pandas-0.24.1.tar.gz (11.8MB)
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 357, in get_provider
module = sys.modules[moduleOrReq]
KeyError: 'numpy'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-8c3o0ycd/pandas/setup.py", line 732, in <module>
ext_modules=maybe_cythonize(extensions, compiler_directives=directives),
File "/tmp/pip-install-8c3o0ycd/pandas/setup.py", line 475, in maybe_cythonize
numpy_incl = pkg_resources.resource_filename('numpy', 'core/include')
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1142, in resource_filename
return get_provider(package_or_requirement).get_resource_filename(
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 359, in get_provider
__import__(moduleOrReq)
ModuleNotFoundError: No module named 'numpy'

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-8c3o0ycd/pandas/
You are using pip version 18.1, however version 19.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
The command '/bin/sh -c pip --no-cache-dir install numpy pandas jupyter' returned a non-zero code: 1

如何完成这个基本设置?

最佳答案

您基本上需要在 alpine 上安装以下内容,以便能够安装 numpy:

apk --no-cache add musl-dev linux-headers g++

尝试以下 Dockerfile:

### Dockerfile
# Created by Baktawar
# Pulling from base Python image

FROM python:3.6.7-alpine3.6

# author of file
LABEL maintainer="Baktawar"

# Set the working directory of the docker image
WORKDIR /app
COPY . /app

# Install native libraries, required for numpy
RUN apk --no-cache add musl-dev linux-headers g++

# Upgrade pip
RUN pip install --upgrade pip

# packages that we need
RUN pip install numpy && \
pip install pandas && \
pip install jupyter

EXPOSE 8888

ENTRYPOINT ["python"]

CMD ["hello_world.py"]

您可能会发现这个要点很有趣:

https://gist.github.com/orenitamar/f29fb15db3b0d13178c1c4dd611adce2

我认为这个关于 Alpine 的软件包也很有趣:

https://pkgs.alpinelinux.org/package/edge/community/x86/py-numpy

更新

为了正确标记图像,请使用语法:

docker build -f <dockerfile> -t <tagname:tagversion> <buildcontext>

对于您来说,这将是:

docker build -t mypythonimage:0.1 .

关于Docker 为 numpy 构建,pandas 给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55032695/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com