這里是我的requirements.txt:
fastapi
pydantic
daphne
這里是Procfile:
web: python3 daphne -b 0.0.0.0 -p 8000 main:app
這里是日志:
$ pip install -r requirements.txt
要求已經滿足:fastapi在/home/petr/.local/lib/python3.8/Site-packages中(來自-r requirements.txt(第1行))。(0.68.0)
要求已經滿足:pydantic in /home/petr/.local/lib/python3.8/site-packages (from -r requirements.txt (line 2)) (1.8.2)
要求已經滿足:daphne in /home/petr/.local/lib/python3.8/Site-packages (from -r requirements.txt (line 3)) (3.0.2)
要求已經滿足:starlette==0.14.2 in /home/petr/.local/lib/python3.8/Site-packages (from fastapi->-r requirements.txt (line 1)) (0.14.2)
已經滿足要求:typing-extensions>=3.7.4.3 in /home/petr/.local/lib/python3.8/site-packages (from pydantic->-r requirements.txt (line 2)) (3.10.0.0)
Requirement already satisfied: autobahn>=0.18 in /home/petr/.local/lib/python3.8/site-packages (from daphne->-r requirements.txt (line 3)) (21.3.1)
要求已經滿足: twisted[tls]>=18.7 in /home/petr/.local/lib/python3.8/Site-packages (from daphne->-r requirements.txt (line 3)) (21.7.0)
已經滿足要求:asgiref<4,>=3.2.10 in /home/petr/.local/lib/python3.8/site-packages (from daphne->-r requirements.txt (line 3) (3.4.1)
已經滿足要求:cryptography>=3.4.6 in /home/petr/.local/lib/python3.8/Site-packages (from autobahn>=0.18->daphne->-r requirements.txt(第3行)) (3.4.7)
要求已經滿足:hyperlink>=21.0.0 in /home/petr/.local/lib/python3.8/site-packages (from autobahn>=0.18->daphne->-r requirements.txt (line 3)) (21.0.0)
要求已經滿足: txaio>=21.2.1 in /home/petr/.local/lib/python3.8/site-packages (from autobahn>=0.18->daphne->-r requirements.txt(第3行)) (21.2.1)
要求已經滿足:attrs>=19.2.0 in /home/petr/.local/lib/python3.8/site-packages (from twisted[tls]>=18.7->daphne->-r requirements.txt(第3行)) (21.2.0)
要求已經滿足:zope.interface>=4.4.2 in /home/petr/.local/lib/python3.8/site-packages (from twisted[tls]>=18.7->daphne->-r requirements.txt(第3行)) (5.4.0)
要求已經滿足:增量>=21.3.0 in /home/petr/.local/lib/python3.8/Site-packages (from twisted[tls]>=18.7->daphne->-r requirements.txt(第3行)) (21.3.0)
要求已經滿足。Automat>=0.8.0 in /home/petr/.local/lib/python3.8/Site-packages (from twisted[tls]>=18.7->daphne->-r requirements.txt(第3行)) (20.2.0)
要求已經滿足: constantly>=15.1 in /home/petr/.local/lib/python3.8/Site-packages (from twisted[tls]>=18.7->daphne->-r requirements.txt(第3行)) (15.1.0)
要求已經滿足:service-identity>=18.1.0; extra == "tls" in /home/petr/.local/lib/python3.8/Site-packages (from twisted[tls]>=18.7->daphne->-r requirements.txt(第3行)) (21.1.0)
已經滿足要求:idna>=2.4; extra == "tls" in /usr/lib/python3/dist-packages (from twisted[tls]>=18.7->daphne->-r requirements.txt(第3行)) (2.8)
要求已經滿足: pyopenssl>=16.0.0; extra == "tls" in /home/petr/.local/lib/python3.8/Site-packages (from twisted[tls]>=18.7->daphne->-r requirements.txt (line 3) (20.0.1)
已經滿足要求:cffi>=1.12 in /home/petr/.local/lib/python3.8/site-packages (from cryptography>=3.4.6->autobahn>=0.18->daphne->-r requirements.txt(第3行)) (1.14.6)
已經滿足的要求:setuptools in /usr/lib/python3/dist-packages (from zope.interface>=4.4.2->twisted[tls]>=18.7->daphne->-r requirements.txt(第3行)) (45.2.0)
已經滿足的要求:6 in /usr/lib/python3/dist-packages (from Automat>=0.8.0->twisted[tls]>=18.7->daphne->-r requirements.txt(第3行)) (1.14.0)
已經滿足要求: pyasn1-modules in /home/petr/.local/lib/python3.8/Site-packages (from service-identity>=18.1.0; extra == "tls"->twisted[tls]>=18.7->daphne->-r requirements.txt(第3行)) (0.2.8)
要求已經滿足: pyasn1 in /home/petr/.local/lib/python3.8/site-packages (from service-identity>=18.1.0; extra == "tls"->twisted[tls]>=18.7->daphne->-r requirements.txt(第3行)) (0.4.8)
已經滿足的要求:/home/petr/.local/lib/python3.8/Site-packages中的pycparser(來自cffi>=1.12->cryptography>=3.4.6->autobahn>=0.18->daphne->-r requirements.txt(第3行)) (2.20)
這里是日志:heroku local web
10:59:51 AM web.1 | python3: 不能打開檔案'daphne'。[Errno 2] 沒有這樣的檔案或目錄
[DONE] 用信號SIGINT殺死所有行程
10:59:51 AM web.1 退出了,退出代碼為null
我運行這個程式的檔案夾看起來是這樣的:
main.py Procfile requirements.txt
而且其中有一個.git檔案夾
謝謝你的幫助!
uj5u.com熱心網友回復:
編輯
把這個放入檔案app.py:
from daphne.cli import CommandLineInterface
CommandLineInterface.entrypoint()
用python3 app.py -b 0.0.0.0 -p 8000 main:app
然后把這個放到Procfile中:
web: python3 app.py -b 0.0.0.0 -p 8000 main:app
無法作業
。不作業是因為__main__不能決議命令列,并且heroku local不支持-m開關(?
你想執行一個模塊,而不是一個檔案。daphne是模塊。所以試試吧
web: python3 -m daphne -b 0. 0.0.0 -p 8000 main:app
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/319742.html
標籤:
