我一直试图在我的流光应用程序中读取一个scipy矩阵文件。应用程序在本地机器上运行,在应用程序或控制台没有任何错误。当部署在Heroku上时,它会提高ValueError: not enough values to unpack (expected 5, got 2)
在co_occurrence_matrix = scipy.io.mmread("./database/matrix.mtx")
线上
我反复检查了以下几点,但不知道从哪里找问题。
- 矩阵是用 创建的
smatrix = scipy.sparse.csr_matrix(matrix)
scipy.isspmatrix(smatrix) #-> returns True
scipy.io.mmwrite("./database/matrix.mtx",smatrix)
- 包括python本身在内的所有库版本在两个应用程序之间是相同的。在控制台用
pip list
检查。并使用pip freeze创建需求文件。 - 文件在git上同步,
git status
返回'up to date '。Heroku使用git上的文件,本地应用运行在同步的文件上。 - 如果有任何区别,.mtx文件通过git lfs上传。
- Heroku成功部署了应用程序,但在streamlit应用程序中,它给出了错误。
完全错误:
File "/app/.heroku/python/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script exec(code, module.__dict__)File "/app/main.py", line 4, in <module> from gorsellestirme_util import set_bg, Plotter, matrix, word_list, main_dfFile "/app/gorsellestirme_util.py", line 30, in <module> matrix, word_list, main_df = matrix_reader()File "/app/.heroku/python/lib/python3.9/site-packages/streamlit/runtime/legacy_caching/caching.py", line 625, in wrapped_func return get_or_create_cached_value()File "/app/.heroku/python/lib/python3.9/site-packages/streamlit/runtime/legacy_caching/caching.py", line 609, in get_or_create_cached_value return_value = non_optional_func(*args, **kwargs)File "/app/gorsellestirme_util.py", line 12, in matrix_reader co_occurrence_matrix = mmread("./database/matrix.mtx")File "/app/.heroku/python/lib/python3.9/site-packages/scipy/io/_mmio.py", line 77, in mmread return MMFile().read(source)File "/app/.heroku/python/lib/python3.9/site-packages/scipy/io/_mmio.py", line 438, in read self._parse_header(stream)File "/app/.heroku/python/lib/python3.9/site-packages/scipy/io/_mmio.py", line 502, in _parse_header self.__class__.info(stream)File "/app/.heroku/python/lib/python3.9/site-packages/scipy/io/_mmio.py", line 234, in info mmid, matrix, format, field, symmetry =
<代码>代码>
关于问题的根源:Heroku文档中明确指出Heroku不支持git-lfs文件。我忘了那一点。
作为一种解决方法,在Heroku元素中有多个构建包。仅供参考,这些构建包也受到Heroku的500Mb文件大小上限的限制。并且必须考虑安全性问题,因为这些构建包需要第三方访问您的git。