在 Heroku 上找不到与 torch==1.5.0+cpu 匹配的分布

Abh*_*ngh 7 python django heroku torch pytorch

我正在尝试部署使用机器学习模型的 Django 应用程序。而机器学习模型需要pytorch来执行。当我尝试部署时,它给了我这个错误

ERROR: Could not find a version that satisfies the requirement torch==1.5.0+cpu (from -r /tmp/build_4518392d43f43bc52f067241a9661c92/requirements.txt (line 23)) (from versions: 0.1.2, 0.1.2.post1, 0.1.2.post2, 0.4.1, 0.4.1.post2, 1.0.0, 1.0.1, 1.0.1.post2, 1.1.0, 1.2.0, 1.3.0, 1.3.1, 1.4.0, 1.5.0)
       ERROR: No matching distribution found for torch==1.5.0+cpu (from -r /tmp/build_4518392d43f43bc52f067241a9661c92/requirements.txt (line 23))
 !     Push rejected, failed to compile Python app.
 !     Push failed
Run Code Online (Sandbox Code Playgroud)

我的requirements.txt是

asgiref==3.2.7
certifi==2020.4.5.1
chardet==3.0.4
cycler==0.10.0
dj-database-url==0.5.0
Django==3.0.6
django-heroku==0.3.1
future==0.18.2
gunicorn==20.0.4
idna==2.9
imageio==2.8.0
kiwisolver==1.2.0
matplotlib==3.2.1
numpy==1.18.4
Pillow==7.1.2
psycopg2==2.8.5
pyparsing==2.4.7
python-dateutil==2.8.1
pytz==2020.1
requests==2.23.0
six==1.14.0
sqlparse==0.3.1
torch==1.5.0+cpu
torchvision==0.6.0+cpu
urllib3==1.25.9
whitenoise==5.0.1

Run Code Online (Sandbox Code Playgroud)

而runtime.txt是python-3.7.5
然而,当我使用命令pip install torch==1.5.0+cpu我使用python 3.7.5和pip 20.0.2时,在我的计算机上安装它并没有给出任何类型的错误。
完整代码在这里
如何解决这个问题我真的需要部署我的应用程序。谢谢

Mic*_*ngo 15

PyTorch 不会通过 PyPI 分发仅 CPU 版本。它们只能通过他们的自定义注册表获得。

如果您在PyTorch - Get Started Locally上选择仅 CPU 版本,您将获得以下说明:

pip install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
Run Code Online (Sandbox Code Playgroud)

由于您不是手动执行 pip install,因此您不能简单地添加-f https://download.pytorch.org/whl/torch_stable.html.

作为替代方案,您可以将其requirements.txt作为独立生产线放入。你把它放在哪里并不重要,但它通常放在最上面。

-f https://download.pytorch.org/whl/torch_stable.html
asgiref==3.2.7
certifi==2020.4.5.1
chardet==3.0.4
cycler==0.10.0
dj-database-url==0.5.0
Django==3.0.6
django-heroku==0.3.1
future==0.18.2
gunicorn==20.0.4
idna==2.9
imageio==2.8.0
kiwisolver==1.2.0
matplotlib==3.2.1
numpy==1.18.4
Pillow==7.1.2
psycopg2==2.8.5
pyparsing==2.4.7
python-dateutil==2.8.1
pytz==2020.1
requests==2.23.0
six==1.14.0
sqlparse==0.3.1
torch==1.5.0+cpu
torchvision==0.6.0+cpu
urllib3==1.25.9
whitenoise==5.0.1
Run Code Online (Sandbox Code Playgroud)


Chr*_*vey 0

我不是火炬专家,但我在其他需要 C 编译器和/或其他库的 AI 软件包中也看到过类似的问题。

  1. 查看 Heroku 上是否有可用的“buildpack”来安装这些依赖项,或者

  2. 更改为使用“容器”分发方法,您可以构建 docker 镜像并将其推送到 heroku 作为部署策略。