【问题标题】:Unable to deploy to heroku due to requirements.txt error由于 requirements.txt 错误,无法部署到 heroku
【发布时间】:2020-07-08 02:18:04
【问题描述】:

我第一次尝试将烧瓶应用程序部署到 heroku。当我做 git push heroku master 我得到以下错误

app.py

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

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

运行时.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```

【问题讨论】:

  • 你能展示一下你的项目目录的结构吗?当您的 procfile 出现问题时,通常会发生这种情况。
  • 我已经包含了一个指向我的项目目录图片的链接。 ty
  • 您的 Procfile 必须如下所示 web: gunicorn app:nameofyourapp nameofyourapp 是您在 app.py 中使用的名称
  • 我尝试了 app:app.py 也 app:app ,但不幸的是都没有成功。你还有什么建议
  • 请出示您的应用 py 文件。另外我假设您正在使用您的 app.py 文件来运行烧瓶应用程序

标签: flask heroku deployment


【解决方案1】:

您正面临这个问题,因为您没有在 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

希望对你有帮助。

【讨论】:

  • 我尝试了您的所有说明,但不幸的是,我仍然收到相同的错误消息。错误,第 7 行的错误似乎表明 setup.py 出了问题。我不完全确定如何解决这个问题。谢谢你的帮助
  • 您有 2 个文件 setup.py 以及 settings.py。 setup.py 在做什么。如果您认为 setup.py 文件是问题的原因,请尝试删除该文件,然后部署它。或者将您的整个项目发布在 GitHub 等网站上,以便我或其他人可以看到您的整个代码并以更好的方式帮助您。顺便抱歉没能帮到你
  • 我刚刚意识到您可能忘记提交所做的更改。尝试提交这些更改,然后运行 ​​git push heroku master
  • 我正在提交更改。我意识到我一直在运行 python 的 mac OS 安装,这可能与它有关。不完全确定。我很快就会上传我的存储库
  • 我添加了一个指向我的 github 的链接
猜你喜欢
  • 2020-07-20
  • 2020-09-27
  • 2018-01-11
  • 2013-10-23
  • 2019-07-21
  • 2020-12-08
  • 2021-08-18
  • 1970-01-01
  • 2012-10-16
相关资源
最近更新 更多