You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Heroku部署Django项目时遇waitress-serve命令未找到错误求助

Django部署Heroku报错:waitress-serve: command not found

首次尝试把Django项目部署到Heroku,一直遇到这个错误:

/bin/bash: line 1: waitress-serve: command not found

我已经删除了requirements.txt,更新了Pipfile和Pipfile.lock,重新安装所有依赖后提交推送,但错误依旧。

Heroku日志

2024-01-25T03:05:40.020168+00:00 heroku[web.1]: State changed from crashed to starting
2024-01-25T03:05:45.036289+00:00 heroku[web.1]: Starting process with command `waitress-serve --port=34599 Website.wsgi:application`
2024-01-25T03:05:45.648621+00:00 app[web.1]: /bin/bash: line 1: waitress-serve: command not found
2024-01-25T03:05:45.722561+00:00 heroku[web.1]: Process exited with status 127
2024-01-25T03:05:45.745857+00:00 heroku[web.1]: State changed from starting to crashed
2024-01-25T03:08:48.965629+00:00 heroku[web.1]: State changed from crashed to starting
2024-01-25T03:08:54.963350+00:00 heroku[web.1]: Starting process with command `waitress-serve --port=52647 Website.wsgi:application`
2024-01-25T03:08:55.529692+00:00 app[web.1]: /bin/bash: line 1: waitress-serve: command not found
2024-01-25T03:08:55.586184+00:00 heroku[web.1]: Process exited with status 127
2024-01-25T03:08:55.607559+00:00 heroku[web.1]: State changed from starting to crashed

Pipfile内容

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
django = "==5.0.1"
django-cors-headers = "==4.3.1"
djoser = "==2.2.2"
djangorestframework = "==3.14.0"
requests = "==2.31.0"
django-heroku = "==0.3.1"
waitress = "==2.1.2"
asgiref = "==3.7.2"
certifi = "==2023.11.17"
cffi = "==1.16.0"
charset-normalizer = "==3.3.2"
cryptography = "==42.0.0"
defusedxml = "==0.8.0rc2"
dj-database-url = "==2.1.0"
django-templated-mail = "==1.1.1"
djangorestframework-simplejwt = "==5.3.1"
idna = "==3.6"
oauthlib = "==3.2.2"
packaging = "==23.2"
psycopg2 = "==2.9.9"
pycparser = "==2.21"
pyjwt = "==2.8.0"
python3-openid = "==3.2.0"
pytz = "==2023.3.post1"
requests-oauthlib = "==1.3.1"
social-auth-app-django = "==5.4.0"
social-auth-core = "==4.5.1"
sqlparse = "==0.4.4"
typing-extensions = "==4.9.0"
tzdata = "==2023.4"
urllib3 = "==2.1.0"
whitenoise = "==6.6.0"

[dev-packages]

[requires]
python_version = "3.12"

Procfile内容

web: waitress-serve --port=$PORT Website.wsgi:application

部署日志

remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Building on the Heroku-22 stack
remote: -----> Using buildpack: heroku/nodejs
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NODE_VERBOSE=false
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote:        engines.node (package.json):  unspecified
remote:        engines.npm (package.json):   unspecified (use default)       
remote:
remote:        Resolving node version 20.x...
remote:        Downloading and installing node 20.11.0...
remote:        Using default npm version: 10.2.4
remote:
remote: -----> Restoring cache
remote:        - npm cache
remote:
remote: -----> Installing dependencies
remote:        Prebuild detected (node_modules already exists)
remote:        Rebuilding any native modules
remote:        rebuilt dependencies successfully
remote:        Installing any new modules (package.json)
remote:
remote:        up to date, audited 44 packages in 465ms
remote:
remote:        3 packages are looking for funding
remote:          run `npm fund` for details
remote:
remote:        found 0 vulnerabilities
remote:
remote: -----> Build
remote:
remote: -----> Caching build
remote:        - npm cache
remote:
remote: -----> Pruning devDependencies
remote:
remote:        up to date, audited 44 packages in 472ms
remote:
remote:        3 packages are looking for funding
remote:          run `npm fund` for details
remote:
remote:        found 0 vulnerabilities
remote:        npm notice
remote:        npm notice New minor version of npm available! 10.2.4 -> 10.4.0
remote:        npm notice Changelog: <https://github.com/npm/cli/releases/tag/v10.4.0>
remote:        npm notice Run `npm install -g npm@10.4.0` to update!
remote:        npm notice
remote:
remote: -----> Build succeeded!
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing...
remote:        Done: 130.5M
remote: -----> Launching...
remote:        Released v42
remote:        https://uchennasporfolio-e180324e16c1.herokuapp.com/ deployed to Heroku
remote:
remote:  !
remote:  ! ## Warning - The same version of this code has already been built: 91b62dc630283c6ca813293a9a08184a3b5e35d2
remote:  !
remote:  ! We have detected that you have triggered a build from source code with version 91b62dc630283c6ca813293a9a08184a3b5e35d2
remote:  ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
remote:  !
remote:  ! If you are developing on a branch and deploying via git you must run:
remote:  !
remote:  !     git push heroku <branchname>:main
remote:  !
remote:  ! This article goes into details on the behavior:
remote:  !   https://devcenter.heroku.com/articles/duplicate-build-version   
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/uchennasporfolio.git
   d92f760..91b62dc  master -> master

问题根源

看部署日志就清楚了:Heroku使用的是nodejs buildpack,完全没处理Python相关的依赖。你的Pipfile里就算写了waitress,Heroku也不会安装,自然找不到waitress-serve命令。

解决步骤

  1. 切换/添加Python buildpack
    打开终端执行:

    # 如果项目不需要Node,直接设置为Python buildpack
    heroku buildpacks:set heroku/python
    
    # 如果项目需要Node(比如前端打包),添加Python buildpack并确保它排在前面
    heroku buildpacks:add --index 1 heroku/python
    
  2. 确保Pipfile.lock已正确提交
    重新生成锁文件并推送:

    pipenv lock --keep-outdated
    git add Pipfile Pipfile.lock
    git commit -m "更新Pipfile.lock"
    git push heroku master
    
  3. 重新部署
    推送代码后,Heroku会用Python buildpack处理你的Pipfile,自动安装所有依赖(包括waitress),之后启动命令就能正常找到waitress-serve了。

额外提醒:Django 5.0.1和Python 3.12在Heroku上是兼容的,但如果后续碰到依赖安装失败,可以检查Pipfile里的包版本是否都支持Python 3.12。


内容的提问来源于stack exchange,提问作者UcheKO

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 15:52:05