When I run git push heroku master
to deploy my app to Heroku I keep getting errors
Heroku Push rejected, failed to compile Python app. Could not find a version that satisfies the requirement
The problem was that the requirements.txt
file I made with
pip freeze > requirements.txt
made a dump of my system wide Python libraries instead of just the libraries in my virtualenv
(as described here). This was very strange because I froze those requirements from my active virtualenv - this behavior should not have been possible.
virtualenv
on windows has always slowed me down so I'm ready to try a new environment manager.
I want to use conda
but am struggling to deploy with it to Heroku. I followed Heroku's instructions for conda build-packs only to get vague/unhelpful errors at build time.
How can I deploy a Python app to Heroku using Conda environments?
Heroku doesn't care if you're using virtualenv
or conda
to manage environments. Using one or the other is mostly irrelevant to the deployment process.
Don't bother with the Conda Environment Buildpack instructions since those are for deploying a remote conda
environment which is not what you are trying to do. You, my friend, are trying to deploy a remote your_app environment.
conda
:$ mkdir dash_app_example
$ cd dash_app_example
$ git init # initializes an empty git repo
environment.yml
file in dash_app_example
:name: dash_app #Environment name
dependencies:
- python=3.6
- pip:
- dash
- dash-renderer
- dash-core-components
- dash-html-components
- plotly
- gunicorn # for app deployment
environment.yml
:$ conda env create
$ source activate dash_app #Writing source is not required on Windows
It should currently be in dash_app:
$ conda info --envs #Current environment is noted by a *
app.py
, requirements.txt
, and a Procfile
:app.py
import dash
import dash_core_components as dcc
import dash_html_components as html
import os
app = dash.Dash(__name__)
server = app.server
app.css.append_css({"external_url": "https://codepen.io/chriddyp/pen/bWLwgP.css"})
app.layout = html.Div([
html.H2('Hello World'),
dcc.Dropdown(
id='dropdown',
options=[{'label': i, 'value': i} for i in ['LA', 'NYC', 'MTL']],
value='LA'
),
html.Div(id='display-value')
])
@app.callback(dash.dependencies.Output('display-value', 'children'),
[dash.dependencies.Input('dropdown', 'value')])
def display_value(value):
return 'You have selected "{}"'.format(value)
if __name__ == '__main__':
app.run_server(debug=True)
Procfile
web: gunicorn app:server
requirements.txt
: describes your Python dependencies. You can fill this file in automatically by running $ pip freeze > requirements.txt
on the command line.
- dash_app_example
--- app.py
--- environment.yml
--- Procfile
--- requirements.txt
Notice how there's no environment data in this directory. That's because conda
unlike virtualenv
stores all your environments in one place neatly away from your app directory. There's no need to .gitignore
those files... they're not here!
$ heroku create my-dash-app # change my-dash-app to a unique name
$ git add . # add all files to git
$ git commit -m 'Initial app boilerplate'
$ git push heroku master # deploy code to heroku
$ heroku ps:scale web=1 # run the app with a 1 heroku "dyno"
Sources:
virtualenv
)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With