首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >由于requirements.txt错误,无法部署到heroku

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

Stack Overflow用户
提问于 2020-07-08 10:18:04
回答 1查看 893关注 0票数 0

我第一次尝试将flask应用程序部署到heroku。当我执行git推送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

代码语言:javascript
复制
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

这是完整的错误日志

代码语言:javascript
复制
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.
代码语言:javascript
复制
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```
EN

回答 1

Stack Overflow用户

发布于 2020-07-09 12:34:01

你之所以面临这个问题,是因为你还没有在你的app.py文件中调用run函数,也就是说,你已经导入了应用程序,但是还没有告诉flask如何处理这个应用程序。正如您所提到的,您的app.py文件如下所示:

代码语言:javascript
复制
from app import app

但您需要指定如何处理该应用程序。因此,您的app.py必须如下所示:

代码语言:javascript
复制
from app import app

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

Procfile必须看起来像这样:

代码语言:javascript
复制
web: gunicorn app:app

希望能有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62786561

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档