在colaboratory中,import 自己写的 py 文件往往会爆出 ModuleNotFoundError: No module named ‘forward' 的错误。

就其原因,是由于 Drive 中文件布局与 Colab 中文件布局是不同的。

如果要在 Colab 中使用 Drive 文件,则需要运行下段代码段,在 Colab 后端安装到你的云端硬盘

from google.colab import drive
drive.mount('/content/drive')

运行

下一步将工作目录更改为Drive根目录

%cd /content/drive/My\ Drive

# List files to make sure we're in the expected directory.
# Your output will look different, showing your own Drive files here.
!ls

运行

我需要加载的 forward.py 文件在 Colab Notebooks 文件夹中,所以代码为

%cd /content/drive/My\ Drive/Colab\ Notebooks

# List files to make sure we're in the expected directory.
# Your output will look different, showing your own Drive files here.
!ls

此时我们就可以 import forward 文件

import forward

运行就不会报错了。

但是当将 import forward 语句放在其他 import 后面时,依然会出现相同的报错情况,但将其放在第一个位置时,就不会报错。

参考:

Neural Networks with Google CoLaboratory | Artificial Intelligence Getting started

【colaboratory】ModuleNotFoundError: No module named 'forward'的更多相关文章

  1. 【Django】ModuleNotFoundError: No module named 'books_ordersschool'

    Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x00000 ...

  2. 【转】modulenotfounderror: no module named 'matplotlib._path'问题的解决

    今天在装matplotlib包的时候遇到这样的问题,在网上找了很长时间没有类似很好的解决方法,最后自己 研究找到了解决的方法. 之前在pycharm里面已经装了matplotlib包,之后觉着下载包挺 ...

  3. 【Python】ModuleNotFoundError: No module named 'matplotlib.pyplot'

    安装好matplotlib后,很激动的建立了一个文件夹matplotlib,并且在其下面建立了,mpl_squraes.py文件,代码编辑完成以后,点击运行,报错如下: 仔细分析了之后,发现是文件夹名 ...

  4. 【AI-人工智能-mmdetection】ModuleNotFoundError: No module named 'mmdet.version'

    在集成 mmdetection 框架时遇到这样的问题. ModuleNotFoundError: No module named 'mmdet.version' mmdetection 框架搭建过程很 ...

  5. 【Linux】`ImportError: No module named '_tkinter'

    在centos7 系统下,导入matplotlib时,出现ImportError: No module named '_tkinter'的错误 首先使用以下命令查看模块是否存在 yum list in ...

  6. 【python】解决No module named _sqlite3的问题

    环境版本说明: centos 7 python3.6.4 django 2.0 在创建django项目时候.报错以下信息 详细错误信息如下: 原因: 未安装sqlite 模块 解决: 1 安装 sql ...

  7. error: ModuleNotFoundError: No module named 'ConfigParser'

    (env2.7) Kaitlyns-Mac:bin kaitlyn$ pip install MySQL-python Looking in indexes: https://pypi.tuna.ts ...

  8. python3 使用flask连接数据库出现“ModuleNotFoundError: No module named 'MySQLdb'”

    本文链接:https://blog.csdn.net/Granery/article/details/89787348 在使用python3连接MySQL的时候出现了 ‘ModuleNotFoundE ...

  9. 从git上pull下的代码,执行时提示:ModuleNotFoundError: No module named '......',解决方法如下:

    方法一: 如果没有安装,如下: 1.PyCharm : file-> setting->Project interpreter–>package2.右侧有个+ 点击3.进入后 搜索p ...

随机推荐

  1. [Git] Undo a commit that has already been pushed to the remote repository

    If we pushed our changes already to the remote repository we have to pay attention to not change the ...

  2. Python连接MySQL的实例代码

    Python连接MySQL的实例代码   MySQLdb下载地址:http://sourceforge.net/projects/mysql-python/ 下载解压缩后放到%Python_HOME% ...

  3. Android Device Monitor工具的使用

    在最新的Android Studio3.x版本中,已经去掉了Android Device Monitor工具,但是不代表Android Device Monitor工具就不能用了,找到sdk的目录: ...

  4. Microsoft® SQL Server® 2008 Express with Tools

    https://www.microsoft.com/zh-cn/download/confirmation.aspx?id=22973

  5. JDK5.0 特性-线程任务执行架构 ScheduledExecutorService

    来自:http://www.cnblogs.com/taven/archive/2011/12/17/2291469.html import java.util.concurrent.Callable ...

  6. MySql绿色版安装步骤和方法,以及配置文件修改,Mysql服务器启动

    MySql绿色版Windows安装步骤和方法,以及配置文件修改,Mysql服务器启动 支持“标准”Markdown / CommonMark和Github风格的语法,也可变身为代码编辑器: 支持实时预 ...

  7. MySQL源代码解读

    第一步: 下载bison-2.4.1-setup.exe链接地址 第二步: 下载cmake-2.8.6-win32-x86.exe链接地址 第三步: 下载MySQL链接地址 G:\Mlearn\mys ...

  8. iOS中TableView小技巧

    摘要: TableView是ios开发中经经常使用到的控件,这里统一记录一下开发中遇到的经常使用小技巧,不断探索更新.也希望大家能够告诉我很多其它经常使用的小技巧啦~一起进步 1.去除多余的列表线条 ...

  9. 【BI】OLTP与OLAP的区别

    概念 OLTP:联机事务处理(On-Line transaction Processing) OLAP:联机分析处理(On-Line Analytical Processing) (1)OLTP是传统 ...

  10. 8、java5线程池之动态缓存线程池newCachedThreadPool

    JDK文档描述 创建一个可根据需要创建新线程的线程池,但是在以前构造的线程可用时将重用它们.对于执行很多短期异步任务的程序而言,这些线程池通常可提高程序性能.调用 execute 将重用以前构造的线程 ...