由于requirements.txt错误,无法部署到heroku

时间:2020-07-08 02:18:04

标签: flask heroku deployment

我正在尝试第一次将flask应用程序部署到heroku。当我执行git push heroku master时,出现以下错误

app.py

cp: cannot stat '/tmp/cache/requirements.txt': No such file or directory

我的procfile看起来像这样 web: gunicorn app.py

runtime.txt python-3.6.1

requirements.txt

bokeh==2.1.1
certifi==2020.6.20
chardet==3.0.4
click==7.1.2
cssmin==0.2.0
Flask==1.1.2
Flask-Assets==2.0
Flask-SQLAlchemy==2.4.3
gunicorn==20.0.4
httplib2==0.18.1
idna==2.9
isort==4.3.21
itsdangerous==1.1.0
Jinja2==2.11.2
jsmin==2.2.2
lazy-object-proxy==1.4.3
libsass==0.20.0
MarkupSafe==1.1.1
mccabe==0.6.1
numpy==1.19.0
opensecrets-crpapi==0.2.2
packaging==20.4
pandas==1.0.5
Pillow==7.2.0
pylint==2.5.3
pyparsing==2.4.7
python-dateutil==2.8.1
python-dotenv==0.13.0
pytz==2020.1
PyYAML==5.3.1
requests==2.24.0
six==1.15.0
SQLAlchemy==1.3.18
toml==0.10.1
tornado==6.0.4
typed-ast==1.4.1
typing-extensions==3.7.4.2
urllib3==1.25.9
webassets==2.0
Werkzeug==1.0.1
whitenoise==5.1.0
wrapt==1.12.1

这是完整的错误日志

remote: -----> Python app detected
remote: cp: cannot stat '/tmp/cache/requirements.txt': No such file or directory
remote: -----> Installing python-3.6.11
remote: -----> Installing pip
remote: -----> Installing SQLite3
remote: -----> Installing requirements with pip
remote:        Obtaining file:///tmp/cache (from -r /tmp/cache/requirements.txt (line 1))
remote:            ERROR: Command errored out with exit status 1:
remote:             command: /app/.heroku/python/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/cache/setup.py'"'"'; __file__='"'"'/tmp/cache/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info
remote:                 cwd: /tmp/cache/
remote:            Complete output (8 lines):
remote:            running egg_info
remote:            creating finalproject.egg-info
remote:            writing finalproject.egg-info/PKG-INFO
remote:            writing dependency_links to finalproject.egg-info/dependency_links.txt
remote:            writing requirements to finalproject.egg-info/requires.txt
remote:            writing top-level names to finalproject.egg-info/top_level.txt
remote:            writing manifest file 'finalproject.egg-info/SOURCES.txt'
remote:            error: package directory 'application' does not exist
remote:            ----------------------------------------
remote:        ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
remote:  !     Push rejected, failed to compile Python app.
app = Flask(__name__)

app.config.from_pyfile('settings.py')

##where to find the database and initialize SQLAlchemy
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///congress.sqlite3'
db = SQLAlchemy(app) 

##option to tell SQLALchemy that we’re way too lazy to do that, and for every model it should just 
#look at the columns that already exist in the table. This is called reflecting
db.Model.metadata.reflect(db.engine)

class Congress(db.Model):
    __tablename__ = 'sen'
    __table_args__ = { 'extend_existing': True }
    id = db.Column(db.Text, primary_key=True) 


## access sass
app.wsgi_app = SassMiddleware(app.wsgi_app, {
    'app': ('static/assets/sass', 'app/static/assets/css/light-bootstrap-dashboard.css', 'app/static/assets/css/light-bootstrap-dashboard.css')
})

# Ensure templates are auto-reloaded
app.config["TEMPLATES_AUTO_RELOAD"] = True

# Custom filter
app.jinja_env.filters["usd"] = usd

from app import routes```

1 个答案:

答案 0 :(得分:0)

您正面临此问题,因为您尚未在app.py文件中调用run函数,即您已导入该应用程序,但尚未告知烧瓶如何使用该应用程序。 如前所述,您的app.py文件如下所示:

from app import app

但是您需要指定如何处理该应用程序。因此,您的app.py必须看起来像这样:

from app import app

if __name__=="__main__":
    app.run()

Procfile必须看起来像这样:

web: gunicorn app:app

希望有帮助。