Django deployment to Heroku error: python: can't open file '/app/backend.manage.py': [Errno 2] No such file or directory , is this a Procfile error?

Django deployment to Heroku error: python: can't open file '/app/backend.manage.py': [Errno 2] No such file or directory , is this a Procfile error?

我正在尝试将一个 django 项目部署到 Heroku,但我遇到了错误,但希望这是最后一个。

2022-03-07T22:03:09.363036+00:00 heroku[release.9772]: Starting process with command `/bin/sh -c 'if curl https://heroku-release-output.s3.amazonaws.com/log-stream?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJ3LIQ2SWG7V76SVQ%2F20220307%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220307T220304Z&X-Amz-Expires=900&X-Amz-SignedHeaders=host&X-Amz-Signature=ddb760b1c36e913b7c0cc984428e3b853cdac67755e4cfa6038cef77a37b6a25 --silent --connect-timeout 10 --retry 3 --retry-delay 1 >/tmp/log-stream; then
2022-03-07T22:03:10.031451+00:00 heroku[release.9772]: State changed from starting to up
2022-03-07T22:03:10.527868+00:00 app[release.9772]: python: can't open file '/app/backend.manage.py': [Errno 2] No such file or directory
2022-03-07T22:03:10.706087+00:00 heroku[release.9772]: Process exited with status 2
2022-03-07T22:03:10.901301+00:00 heroku[release.9772]: State changed from up to complete
2022-03-07T22:02:37.000000+00:00 app[api]: Build started by user email@protonmail.com
2022-03-07T22:03:03.734406+00:00 app[api]: Deploy 922870fe by user email@protonmail.com
2022-03-07T22:03:03.734406+00:00 app[api]: Running release v26 commands by user email@protonmail.com
2022-03-07T22:03:05.039171+00:00 app[api]: Starting process with command `/bin/sh -c 'if curl $HEROKU_RELEASE_LOG_STREAM --silent --connect-timeout 10 --retry 3 --retry-delay 1 >/tmp/log-stream; then
2022-03-07T22:03:05.039171+00:00 app[api]:   chmod u+x /tmp/log-stream
2022-03-07T22:03:05.039171+00:00 app[api]:   /tmp/log-stream /bin/sh -c '"'"'python backend.manage.py makemigrations - - no-input'"'"'
2022-03-07T22:03:05.039171+00:00 app[api]: else
2022-03-07T22:03:05.039171+00:00 app[api]:   python backend.manage.py makemigrations - - no-input
2022-03-07T22:03:05.039171+00:00 app[api]: fi'` by user email@protonmail.com
2022-03-07T22:03:12.919074+00:00 app[api]: Release v26 command failed by user email@protonmail.com
2022-03-07T22:03:15.000000+00:00 app[api]: Build succeeded

当我尝试使用命令 heroku local:

在本地计算机的虚拟环境中 运行 程序时
6:06:35 PM web.1 |  [2022-03-07 18:06:35 -0400] [33412] [INFO] Starting gunicorn 20.1.0
6:06:35 PM web.1 |  [2022-03-07 18:06:35 -0400] [33412] [ERROR] Connection in use: ('0.0.0.0', 5000)
6:06:35 PM web.1 |  [2022-03-07 18:06:35 -0400] [33412] [ERROR] Retrying in 1 second.
6:06:36 PM web.1 |  [2022-03-07 18:06:36 -0400] [33412] [ERROR] Connection in use: ('0.0.0.0', 5000)

等等等等。

我怀疑这与我的 Procfile 有关。不可否认,我不太确定如何设置它。我目前在 Procfile:

web: gunicorn --pythonpath backend.feh backend.feh.wsgi --log-file - 
release: python backend.manage.py makemigrations - - no-input

我的目录结构是这样的:

runtime.txt
requirements.txt
Procfile
backend/
    |-- __init__.py
        api/
        feh/
            |-- __init__.py
                errorlog
                settings.py
                urls.py
                wsgi.py
        static/
        db.sqlite3
        manage.py
scraper.py

我肯定我的 Procfile 是导致此问题的原因,但我不知道如何调试它。至少,项目 运行 在我的 venv 上没问题。提前致谢!

您的 Procfile 中的两个进程均未正确指定。

  • Web 命令的 --pythonpath 应该只是 backend 并且它应该接收虚线路径 feh.wsgi 作为参数:

    web: gunicorn --pythonpath backend feh.wsgi --log-file -
    
  • 释放命令引用了一个名为backend.manage.py的文件:

    release: python backend.manage.py makemigrations - - no-input
    

    该参数应该是文件的路径,而不是带点的 Python 模块,并且 - - no-input 应该是单个参数 --no-input。试试这个:

    release: python backend/manage.py makemigrations --no-input