Home > OS >  Getting python3: can't open file 'daphne': [Errno 2] No such file or directory in Her
Getting python3: can't open file 'daphne': [Errno 2] No such file or directory in Her

Time:09-17

Here are my requirements.txt:

fastapi
pydantic
daphne

Here is the Procfile:

web: python3 daphne -b 0.0.0.0 -p 8000 main:app

Here is the log:

$ pip install -r requirements.txt

Requirement already satisfied: fastapi in /home/petr/.local/lib/python3.8/site-packages (from -r requirements.txt (line 1)) (0.68.0)
Requirement already satisfied: pydantic in /home/petr/.local/lib/python3.8/site-packages (from -r requirements.txt (line 2)) (1.8.2)
Requirement already satisfied: daphne in /home/petr/.local/lib/python3.8/site-packages (from -r requirements.txt (line 3)) (3.0.2)
Requirement already satisfied: starlette==0.14.2 in /home/petr/.local/lib/python3.8/site-packages (from fastapi->-r requirements.txt (line 1)) (0.14.2)
Requirement already satisfied: 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)
Requirement already satisfied: twisted[tls]>=18.7 in /home/petr/.local/lib/python3.8/site-packages (from daphne->-r requirements.txt (line 3)) (21.7.0)
Requirement already satisfied: asgiref<4,>=3.2.10 in /home/petr/.local/lib/python3.8/site-packages (from daphne->-r requirements.txt (line 3)) (3.4.1)
Requirement already satisfied: cryptography>=3.4.6 in /home/petr/.local/lib/python3.8/site-packages (from autobahn>=0.18->daphne->-r requirements.txt (line 3)) (3.4.7)
Requirement already satisfied: 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)
Requirement already satisfied: txaio>=21.2.1 in /home/petr/.local/lib/python3.8/site-packages (from autobahn>=0.18->daphne->-r requirements.txt (line 3)) (21.2.1)
Requirement already satisfied: attrs>=19.2.0 in /home/petr/.local/lib/python3.8/site-packages (from twisted[tls]>=18.7->daphne->-r requirements.txt (line 3)) (21.2.0)
Requirement already satisfied: zope.interface>=4.4.2 in /home/petr/.local/lib/python3.8/site-packages (from twisted[tls]>=18.7->daphne->-r requirements.txt (line 3)) (5.4.0)
Requirement already satisfied: incremental>=21.3.0 in /home/petr/.local/lib/python3.8/site-packages (from twisted[tls]>=18.7->daphne->-r requirements.txt (line 3)) (21.3.0)
Requirement already satisfied: Automat>=0.8.0 in /home/petr/.local/lib/python3.8/site-packages (from twisted[tls]>=18.7->daphne->-r requirements.txt (line 3)) (20.2.0)
Requirement already satisfied: constantly>=15.1 in /home/petr/.local/lib/python3.8/site-packages (from twisted[tls]>=18.7->daphne->-r requirements.txt (line 3)) (15.1.0)
Requirement already satisfied: 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 (line 3)) (21.1.0)
Requirement already satisfied: idna>=2.4; extra == "tls" in /usr/lib/python3/dist-packages (from twisted[tls]>=18.7->daphne->-r requirements.txt (line 3)) (2.8)
Requirement already satisfied: 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)
Requirement already satisfied: cffi>=1.12 in /home/petr/.local/lib/python3.8/site-packages (from cryptography>=3.4.6->autobahn>=0.18->daphne->-r requirements.txt (line 3)) (1.14.6)
Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (from zope.interface>=4.4.2->twisted[tls]>=18.7->daphne->-r requirements.txt (line 3)) (45.2.0)
Requirement already satisfied: six in /usr/lib/python3/dist-packages (from Automat>=0.8.0->twisted[tls]>=18.7->daphne->-r requirements.txt (line 3)) (1.14.0)
Requirement already satisfied: 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 (line 3)) (0.2.8)
Requirement already satisfied: 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 (line 3)) (0.4.8)
Requirement already satisfied: pycparser in /home/petr/.local/lib/python3.8/site-packages (from cffi>=1.12->cryptography>=3.4.6->autobahn>=0.18->daphne->-r requirements.txt (line 3)) (2.20)

Here is the log: heroku local web

10:59:51 AM web.1 |  python3: can't open file 'daphne': [Errno 2] No such file or directory
[DONE] Killing all processes with signal  SIGINT
10:59:51 AM web.1 Exited with exit code null

The folder I'm running this in looks like this:

main.py  Procfile  requirements.txt

And there is a .git folder in it

Thank you for your help!

CodePudding user response:

Edit

Put this into file app.py:

from daphne.cli import CommandLineInterface
CommandLineInterface.entrypoint()

Test it with python3 app.py -b 0.0.0.0 -p 8000 main:app

Then put this into the Procfile:

web: python3 app.py -b 0.0.0.0 -p 8000 main:app

Not Working

Not wrorking because __main__ does not parse command line, and heroku local does not support the -m switch (?).

You want to execute a module, not a file. daphne is the module. So try

web: python3 -m daphne -b 0.0.0.0 -p 8000 main:app
  • Related