简体   繁体   English

spaCy 和 Docker:无法“dockerize”使用 spaCy 模块的 Flask 应用程序

[英]spaCy and Docker: can't "dockerize" Flask app that uses spaCy modules

I'm trying to install SpaCy on my docker image but it always fails.我正在尝试在我的 docker 映像上安装 SpaCy,但它总是失败。 First it was on my requirements.txt file, but it failed right away.首先它在我的 requirements.txt 文件中,但它立即失败了。 Later on I tried running a separate RUN instruction for pip to install it in isolation but it also failed.后来我尝试为 pip 运行单独的 RUN 指令以单独安装它,但它也失败了。

Here's my Dockerfile content:这是我的 Dockerfile 内容:

FROM python:3.6-alpine
WORKDIR /sentenceSimilarity
ADD . /sentenceSimilarity
RUN pip install -r requirements.txt
RUN pip install -U pip setuptools wheel
RUN pip install -U spacy
RUN python -m spacy download en_core_web_sm
CMD ["python", "app.py"]

I ended up deleting everything from my requirements.txt file except for Flask and the issue is always stumbled upon the line in which Spacy comes, the only difference now is that it takes a huge time to fail.我最终从我的 requirements.txt 文件中删除了除 Flask 之外的所有内容,并且问题总是偶然发现 Spacy 出现的那一行,现在唯一的区别是它需要很长时间才能失败。 See screenshot:看截图:

在此处输入图像描述

Observing a bit, I think pip has been iterating to check which version might suit, from newest to oldest.稍微观察一下,我认为 pip 一直在迭代检查哪个版本可能适合,从最新到最旧。 But none of those at the end gets installed.但是最后没有一个被安装。

I've seen others with similar issues with SpaCy, but no apparent solution.我见过其他人与 SpaCy 有类似问题,但没有明显的解决方案。

Can someone suggest an approach I could use to fix this?有人可以建议我可以用来解决此问题的方法吗? Thanks in advance.提前致谢。

The spacy installation extremely slow in docker Github issue explains the problem with the Alpine Python docker (I see you have FROM python:3.6-alpine in your dockerfile): The spacy installation extremely slow in docker Github issue explains the problem with the Alpine Python docker (I see you have FROM python:3.6-alpine in your dockerfile):

If you're using an Alpine Linux container, you should probably not: it's a bad choice for Python because none of the PyPi wheels will work, so you'll have to rebuild everything.如果您使用的是 Alpine Linux 容器,您可能不应该这样做:对于 Python 来说,这是一个糟糕的选择,因为 PyPi 轮子都不起作用,所以您必须重建所有东西。 If you're determined to use Alpine Linux you should host yourself a wheelhouse so that you don't have to rebuild the wheels all the time.如果您决定使用 Alpine Linux,您应该为自己配备一个驾驶室,这样您就不必一直重建车轮。

So, you need to use another image, eg a slim docker image, as recommended by @mkkeffeler .因此,您需要使用另一个图像,例如 @mkkeffeler 推荐的纤薄 docker 图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM