pythonherokudeploymentasgijustpy

Deploying JustPy to Heroku


I'm trying to deploy a JustPy app on Heroku. I'm new to both.

Base code, from 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)

To deploy to a Heroku account, get the Heroku tools from: https://devcenter.heroku.com/articles/heroku-cli

From your project folder:

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

...and I get the following errors:

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

[Updated:] I'm getting this further error:

-----> 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

What am I doing wrong? All help gratefully received!


Solution

  • See https://devcenter.heroku.com/articles/getting-started-with-python?singlepage=true#define-a-procfile

    You just need three files:

    1. requirements.txt
    2. Procfile
    3. hello_world.py

    requirements.txt

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

    Procfile

    web: python hello_world.py
    

    hello_world.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')
    

    The main issue is to pick up the assigned port from heroku via the "PORT" environment variable and to set the host to '0.0.0.0' to listen to all interfaces.

    See

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