gpt4 book ai didi

python - 尝试使用Torch/PyTorch创建Docker镜像时出现MemoryError

转载 作者:行者123 更新时间:2023-12-02 20:46:24 31 4
gpt4 key购买 nike

我遵循this tutorial为flask应用程序创建Docker镜像。该应用程序取决于Torch / PyTorch。因此,我的requirements.txt文件如下所示。

flask
flask 芯
火炬
火炬视觉
Pandas

然后,我的Dockerfile如下所示。

来自ubuntu:latest
标签我的公司“info@mycompany.com”
运行apt-get update -y
运行apt-get install -y python-pip python-dev build-essential
复制。 / app
WORKDIR / app
RUN pip install -vvv --no-cache-dir -r requirements.txt
ENTRYPOINT [“python3”]
CMD [“app.py”]

当我在命令docker build -t flask-sample-one:latest .中键入命令时,我的Mac上出现以下错误消息(当pip尝试安装割炬时发生)。

异常(exception):
追溯(最近一次通话):
主目录中的文件“/usr/lib/python2.7/dist-packages/pip/basecommand.py”,第215行
状态= self.run(选项,参数)
运行中的文件“/usr/lib/python2.7/dist-packages/pip/commands/install.py”,第353行
wb.build(autobuilding =真)
在构建中,文件“/usr/lib/python2.7/dist-packages/pip/wheel.py”,行749
self.requirement_set.prepare_files(self.finder)
在prepare_files中的行380中,文件“/usr/lib/python2.7/dist-packages/pip/req/req_set.py”
ignore_dependencies = self.ignore_dependencies))
_prepare_file中的第620行“/usr/lib/python2.7/dist-packages/pip/req/req_set.py”文件
session = self.session,hash = hash)
unpack_url中的文件“/usr/lib/python2.7/dist-packages/pip/download.py”,第821行
哈希=哈希
unpack_http_url中的文件“/usr/lib/python2.7/dist-packages/pip/download.py”,第659行
哈希)
_download_http_url中的文件“/usr/lib/python2.7/dist-packages/pip/download.py”,第882行
_download_url(resp,链接,content_file,哈希)
_download_url中的文件“/usr/lib/python2.7/dist-packages/pip/download.py”,第603行
hashes.check_against_chunks(downloaded_chunks)
在check_against_chunks中的文件“/usr/lib/python2.7/dist-packages/pip/utils/hashes.py”,第46行
对于大块:
文件“/usr/lib/python2.7/dist-packages/pip/download.py”,第571行,以书面形式
对于大块:
文件“/usr/lib/python2.7/dist-packages/pip/utils/ui.py”,第139行,位于iter中
对于其中的x:
在resp_read中的文件“/usr/lib/python2.7/dist-packages/pip/download.py”,第560行
解码内容=否):
流中的文件“/usr/share/python-wheels/urllib3-1.22-py2.py3-none-any.whl/urllib3/response.py”,第436行
数据= self.read(amt = amt,decode_content = decode_content)
已读取文件“/usr/share/python-wheels/urllib3-1.22-py2.py3-none-any.whl/urllib3/response.py”,第384行
数据= self._fp.read(amt)
读取文件“/usr/share/python-wheels/CacheControl-0.11.7-py2.py3-none-any.whl/cachecontrol/filewrapper.py”,第63行
self._close()
_close中的文件“/usr/share/python-wheels/CacheControl-0.11.7-py2.py3-none-any.whl/cachecontrol/filewrapper.py”,第50行
self .__ callback(self .__ buf.getvalue())
在cache_response中的文件“/usr/share/python-wheels/CacheControl-0.11.7-py2.py3-none-any.whl/cachecontrol/controller.py”,行275
self.serializer.dumps(request,response,body = body),
在转储中的文件“/usr/share/python-wheels/CacheControl-0.11.7-py2.py3-none-any.whl/cachecontrol/serialize.py”,第55行
“body”:_b64_encode_bytes(body),
文件“/usr/share/python-wheels/CacheControl-0.11.7-py2.py3-none-any.whl/cachecontrol/serialize.py”,第12行,_b64_encode_bytes
返回base64.b64encode(b).decode(“ascii”)
MemoryError
命令'/ bin / sh -c pip install -vvv -r requirements.txt'返回了非零代码:2

我不确定MemoryError的来源。我试图在具有16 GB RAM的Macbook Pro上构建docker镜像。关于正在发生的事情或如何使用Python创建docker镜像的任何想法吗?

在一个AWS EC2实例上,出现以下错误。

为pytorch运行setup.py install:已启动
运行命令/ usr / bin / python -u -c“import setuptools,tokenize; __ file __ ='/ tmp / pip-build-SeBh33 / pytorch / setup.py'; f = getattr(tokenize,'open',open)( __file __); code = f.read()。replace('\ r \ n','\ n'); f.close(); exec(compile(code,__file__,'exec'))“install --record /tmp/pip-5jxyuS-record/install-record.txt-单一版本-外部管理-编译
追溯(最近一次通话):
文件“”,第1行,位于
在第13行的文件“/tmp/pip-build-SeBh33/pytorch/setup.py”
引发异常(消息)
异常(exception):您应该从http://pytorch.org安装pytorch
为pytorch运行setup.py install:状态为“错误”
打扫干净...
在/ tmp / pip-build-SeBh33 / pytorch中删除源
命令“/ usr / bin / python -u -c”导入setuptools,标记化; __ file __ ='/ tmp / pip-build-SeBh33 / pytorch / setup.py'; f = getattr(tokenize,'open',open)( __file __); code = f.read()。replace('\ r \ n','\ n'); f.close(); exec(compile(code,__file__,'exec'))“install --record /tmp/pip-5jxyuS-record/install-record.txt-“单一版本-外部管理-编译”失败,错误代码为/ tmp / pip-build-SeBh33 / pytorch /
异常信息:
追溯(最近一次通话):
主目录中的文件“/usr/lib/python2.7/dist-packages/pip/basecommand.py”,第215行
状态= self.run(选项,参数)
运行中的文件“/usr/lib/python2.7/dist-packages/pip/commands/install.py”,第360行
prefix = options.prefix_path,
在安装中,文件“/usr/lib/python2.7/dist-packages/pip/req/req_set.py”,第784行
**夸克
在安装中,文件“/usr/lib/python2.7/dist-packages/pip/req/req_install.py”,第878行
spinner = spinner,
在call_subprocess中的第725行,文件“/usr/lib/python2.7/dist-packages/pip/utils/__init__.py”
%(command_desc,proc.returncode,cwd))
InstallationError:命令“/ usr / bin / python -u -c”导入setuptools,标记化; __ file __ ='/ tmp / pip-build-SeBh33 / pytorch / setup.py'; f = getattr(标记化,'打开',打开)(__ file __); code = f.read()。replace('\ r \ n','\ n'); f.close(); exec(compile(code,__file__,'exec')))“安装- -record /tmp/pip-5jxyuS-record/install-record.txt-“单一版本-外部管理-编译”失败,错误代码为/ tmp / pip-build-SeBh33 / pytorch /
命令'/ bin / sh -c pip install -vvv --no-cache-dir -r requirements.txt'返回非零代码:1

有什么想法吗?我只是在尝试构建具有少量依赖关系的docker镜像,以便可以从flask应用程序提供PyTorch模型。我不确定是否有关于此操作的教程(暂时找不到)。

最佳答案

如果有人感兴趣,我可以按照以下方式将PyTorch安装到docker容器中。

我将requirements.txt修改为如下所示。

flask
flask-cors
pandas

然后,我将 Dockerfile修改为如下所示。这很古怪,不遵循使用pip安装Python软件包的常规方法,但是可以使用。请注意,我必须先安装Python 3,再安装PyTorch wheel,最后再安装 torchvision进行pip安装。
FROM ubuntu:latest
LABEL My Company "info@mycompany.com"
RUN apt-get update -y
RUN apt-get install -y python-pip python-dev build-essential
RUN apt-get install -y python3.6
RUN apt-get install -y python3-pip
COPY . /app
WORKDIR /app
RUN pip3 install -vvv --no-cache-dir -r requirements.txt
RUN pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.1-cp36-cp36m-linux_x86_64.whl
RUN pip3 install torchvision
ENTRYPOINT ["python3"]
CMD ["app.py"]

关于python - 尝试使用Torch/PyTorch创建Docker镜像时出现MemoryError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52782864/

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