首页 > 解决方案 > 部署 Dash 应用程序时出现 Heroku 应用程序错误:“OSError:xlwings 需要安装 Excel,因此仅适用于 Windows 和 macOS。”

问题描述

当我尝试将 Dash 应用程序部署到 Heroku 时出现错误。

这是我第一次使用 Heroku、Dash 和 Plotly。我正在尝试为我的团队部署此应用程序。我还没有将代码保存在 GitHub 上。我得到的错误是“未能将一些裁判推到……”

完整的问题如下所示。

remote:        Collecting xlwings==0.20.4
remote:          Downloading xlwings-0.20.4.tar.gz (647 kB)
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/pip-install-pamtz4zz/xlwings/setup.py'"'"'; __file__='"'"'/tmp/pip-install-pamtz4zz/xlwings/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-jxny1ijq
remote:                 cwd: /tmp/pip-install-pamtz4zz/xlwings/
remote:            Complete output (5 lines):
remote:            Traceback (most recent call last):
remote:              File "<string>", line 1, in <module>
remote:              File "/tmp/pip-install-pamtz4zz/xlwings/setup.py", line 32, in <module>
remote:                raise OSError("xlwings requires an installation of Excel and therefore only works on Windows and macOS. To enable the installation on Linux nevertheless, do: export INSTALL_ON_LINUX=1; pip install xlwings")
remote:            OSError: xlwings requires an installation of Excel and therefore only works on Windows and macOS. To enable the installation on Linux nevertheless, do: export INSTALL_ON_LINUX=1; pip install xlwings
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.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !   Push rejected to dash.
remote: 
To https://git.heroku.com/dash.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/dash.git'

标签: pythonherokuplotly-dashxlwings

解决方案


xlwings 需要安装 Excel,因此仅适用于 Windows 和 macOS

Heroku 不运行 Windows 或 macOS(它运行 Linux),因此您不能xlwings在 Heroku 上使用。

设置INSTALL_ON_LINUX=1会绕过此检查并让安装继续进行,但它不会改变 Heroku 运行的是 Linux,而不是 Windows 或 macOS 的事实,而且它当然不提供 Excel。

也许你对如何xlwings工作感到困惑?您可能在本地运行 Windows 或 macOS,并且您可能有 Excel 可用。但是您部署到 Heroku 的代码在那里运行,并且无法访问您机器上的 Excel。

您可能想通读一下客户端和服务器端编程之间的区别是什么?您部署到 Heroku 的代码运行server-side

我不知道你想用 Excel 做什么,但还有其他可用于 Python 的 Excel 库。类似的东西openpyxl可能会xlwings在您的应用程序中取代。它应该在 Heroku 上运行。

但它可能不会做你想做的事——<code>xlwings 可以做一些不能做的整洁的事情openpyxl


推荐阅读