当我运行git push heroku master
将我的应用部署到Heroku时,我不断收到错误
Heroku Push被拒绝,无法编译Python应用程序。找不到满足要求的版本
问题在于我使用
创建的requirements.txt
文件
pip freeze > requirements.txt
转储了我的系统范围的Python库,而不仅仅是virtualenv
(as described here)中的库。这很奇怪,因为我从我的活跃的virtualenv中冻结了这些要求 - 这种行为应该是不可能的。
virtualenv
总是让我失望,所以我准备尝试一个新的环境经理。
我想使用conda
,但我正在努力将其部署到Heroku。我跟着Heroku's instructions for conda build-packs只是为了在构建时获得模糊/无用的错误。
如何使用Conda环境将Python应用程序部署到Heroku?
答案 0 :(得分:5)
如果您使用virtualenv
或conda
来管理环境,Heroku并不在意。使用其中一个与部署过程无关。
不要理会Conda Environment Buildpack指令,因为这些指令用于部署远程conda
环境,而这不是您尝试做的。您,我的朋友,正在尝试部署远程 your_app 环境。
conda
:$ mkdir dash_app_example
$ cd dash_app_example
$ git init # initializes an empty git repo
environment.yml
中创建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
目前应该在dash_app中:
$ conda info --envs #Current environment is noted by a *
app.py
,requirements.txt
和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
:描述您的Python依赖项。您可以使用以下命令自动填写此文件:
$ pip freeze > requirements.txt
- dash_app_example
--- app.py
--- environment.yml
--- Procfile
--- requirements.txt
请注意此目录中没有环境数据。这是因为conda
与virtualenv
不同,它将您的所有环境存储在一个远离您的应用目录的地方。没有.gitignore
这些文件......他们不在这里!
$ 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"
来源: