【问题标题】:Module not recognized after run on Google Colab在 Google Colab 上运行后模块无法识别
【发布时间】:2021-10-09 05:13:42
【问题描述】:

我尝试在 Google Colab 上从 github 运行此模型。 (https://github.com/amacd31/gr2m) 为此,我下载了 repo 并上传到了我的 Google Drive。 我在stackoverflow的其他帖子中找到了这个sn-p来指定工作目录:

import os
path = "/content/drive/MyDrive/hydro/final/gr2m-master/" #/content is pretty much the root. you can choose other path in your colab workspace
os.chdir(path)

目录在这里:(在运行test_gr2m.py之前,要先执行model.py)

首先我运行了模型并执行了以下几行来运行模型

!python /content/drive/MyDrive/hydro/final/gr2m-master/gr2m/_version.py
!python /content/drive/MyDrive/hydro/final/gr2m-master/gr2m/model.py

然后我执行了测试

!python /content/drive/MyDrive/hydro/final/gr2m-master/tests/test_gr2m.py

但是当我尝试运行模型时,它会产生:

回溯(最近一次通话最后一次):

中的文件“/content/drive/MyDrive/maestria/2021/2021-I/Hidrologia/Trabajo_grupal/gr2m-master/tests/test_gr2m.py”,第 8 行 从 gr2m 导入 gr2m
ModuleNotFoundError: 没有名为“gr2m”的模块

【问题讨论】:

    标签: python google-colaboratory modulenotfounderror


    【解决方案1】:

    这可能是您没有在 google colab 的同一会话/实例中运行的原因。

    【讨论】:

    • 对不起,我是新手,不知道如何在同一个会话/实例中运行。你能解释一下吗?
    猜你喜欢
    • 2020-10-17
    • 2021-11-10
    • 2019-02-28
    • 1970-01-01
    • 1970-01-01
    • 2010-12-13
    • 2018-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多