【问题标题】:share.streamlit can't find pkl fileshare.streamlit 找不到 pkl 文件
【发布时间】:2021-12-14 11:59:06
【问题描述】:

我有一个在 localhost 上运行良好的流线型应用程序。但是,当部署到 share.streamlit 时,FileNotFoundError 不断弹出 我已经将应用程序更改为使用 Python 3.9(与我在本地机器上使用的版本相同)。 这是回购的链接:https://github.com/leminhds/breast-cancer-diabetes-and-liver-disease-predictor 这是应用程序的链接:https://share.streamlit.io/leminhds/breast-cancer-diabetes-and-liver-disease-predictor/app/app.py

任何帮助将不胜感激,因为过去几个小时我一直在尝试重命名路径、重新定位 pkl 文件的不同组合,但没有任何效果。谢谢

【问题讨论】:

  • 你能在这里复制粘贴确切的错误信息吗?那么我们在谈论什么文件?也许查看 streamlit 共享中的日志历史记录。还要确保你在 github 上的 requirements.txt 文件中列出了所有必需的 python 模块。
  • 错误消息是:FileNotFoundError: [Errno 2] No such file or directory: 'liver_model.pkl' 尽管文件存在。所有模块也列在 requirements.txt

标签: python pickle streamlit


【解决方案1】:

问题来自我使用相对路径这一事实。当上传到 Share.streamlit 时,它不再起作用了。

为了克服这个问题,我简单地使用 pathlib 模块在 github 上找到文件夹的根目录。示例:

from pathlib import Path

pkl_path = Path(__file__).parents[1] / 'pages/liver_model.pkl'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多