正在将JustPy部署到Heroku

hi3rlvi2  于 2022-11-13  发布在  其他
关注(0)|答案(1)|浏览(197)

我想在Heroku上部署一个JustPy应用程序。我对这两个都不熟悉。
基本代码,来自https://justpy.io/tutorial/getting_started/

# saved as app.py
import justpy as jp
app = jp.app # added for deployment

def hello_world():
    wp = jp.WebPage()
    jp.Hello(a=wp)
    return wp

jp.justpy(hello_world)

要部署到Heroku帐户,请从以下位置获取Heroku工具:https://devcenter.heroku.com/articles/heroku-cli
从您的项目文件夹:

pip install gunicorn
pip freeze > requirements.txt
# create Procfile web:- gunicorn app:app
# create runtime.txt:- Python 3.9.5 
heroku login
heroku create justpyhi
git init
git add .   
git config --global user.email "myemail@hotmail.com"
git config --global user.name "whateverusername"
git commit -m "first commit"
heroku git:remote --app justpyhi
git push heroku master
heroku open

...我收到以下错误:

Starting process with command `gunicorn mainheroku l`
app[web.1]: bash: gunicorn: command not found
heroku[web.1]: Process exited with status 127
heroku[web.1]: State changed from starting to crashed
heroku[web.1]: State changed from crashed to starting
app[api]: Build succeeded

[更新:]我得到这个进一步的错误:

-----> Building on the Heroku-20 stack
-----> Using buildpack: heroku/python
-----> App not compatible with buildpack: https://buildpack-registry.s3.amazonaws.com/buildpacks/heroku/python.tgz
       More info: https://devcenter.heroku.com/articles/buildpacks#detection-failure
 !     Push failed

我做错了什么?所有的帮助都感激不尽!

3yhwsihp

3yhwsihp1#

请访问https://devcenter.heroku.com/articles/getting-started-with-python?singlepage=true#define-a-procfile
您只需要三个文件:

  1. requirements.txt
    1.过程文件
    1.您好_世界.py

需求.txt

# https://github.com/justpy-org/justpy
# install justpy
justpy

过程文件

web: python hello_world.py

你好世界.py

# saved as app.py
import justpy as jp
import os
app = jp.app # added for deployment

def hello_world():
    wp = jp.WebPage()
    jp.Hello(a=wp)
    return wp

port=os.environ['PORT']
jp.justpy(hello_world,port=port,host='0.0.0.0')

主要问题是通过“PORT”环境变量从heroku获取分配的端口,并将主机设置为“0.0.0.0”以侦听所有接口。
请参阅

  1. https://stackoverflow.com/a/15693371/1497139

相关问题