[英]no module named … try to importcustom python module from a notebook in google Colab
In a google drive, suppose a jupyter notebook and a python file my_module.py copied in the same directory. 在Google驱动器中,假设Jupyter笔记本和python文件my_module.py复制到同一目录中。 How to import my_module from the notebook when run with google colaboratory? 使用google colaboratory运行时如何从笔记本中导入my_module?
When the notebook is run locally, import my_module
just works. 当笔记本在本地运行时, import my_module
才起作用。
At the bottom of the welcome notebook at colab.research.google.com there's a link to an example notebook titled "Loading and saving data: local files, Drive, Sheets, Google Cloud Storage" ( https://colab.research.google.com/notebook#fileId=/v2/external/notebooks/io.ipynb ). 在欢迎笔记本的底部colab.research.google.com上,有一个示例笔记本的链接,标题为“加载和保存数据:本地文件,驱动器,表格,Google Cloud Storage”( https://colab.research.google .com / notebook#fileId = / v2 / external / notebooks / io.ipynb )。 This gives recipes for how to copy files from Google Drive to the colaboratory runtime which you can use to copy your module code so it will be visible to the runtime's import machinery. 这提供了有关如何将文件从Google云端硬盘复制到相关运行时的食谱,您可以用来复制模块代码,以便对运行时的导入机制可见。
I has same problem before i fixed it. 在修复之前,我有同样的问题。 there is few way. 几乎没有办法。
1.Use right python version, google colaboratory have 2 python version 2.7 and 3.6.1. 1.使用正确的python版本,google colaboratory有2个python版本2.7和3.6.1。
2.Add init .py blank content in directory, example: 2.在目录中添加init .py空白内容,例如:
dir/
__init__.py
my_module.py
yournotebook.ipynb
3.Remove all pycache *.pyc in dir/ 3.删除dir /中的所有pycache * .pyc
cd dir
!rm *pyc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.