简体   繁体   English

没有名为…的模块…尝试从google Colab中的笔记本导入自定义python模块

[英]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.

相关问题 ModuleNotFoundError:没有名为“google.colab”的模块 - Python - ModuleNotFoundError: No module named 'google.colab' - Python 导入错误:在 Colab google 中没有名为 ... 的模块 - ImportError: No module named ... in Colab google 无法在 google colab notebook 中使用来自 googlesearch 模块的搜索方法 - Unable to use search method from googlesearch module in google colab notebook Google colab:找不到名为 pytextrank 的模块(以前使用同一笔记本工作过) - Google colab: No module named pytextrank can be found (worked previously with the same notebook) Google Colab 中没有名为“utils.utils”的模块 - No module named 'utils.utils' in Google Colab 如何在Google Colab中解决“没有名为“工具”的模块”? - How to solve “No module named 'tools'” in google colab? Google colab:ModuleNotFoundError:没有名为“pymorphy2”的模块 - Google colab : ModuleNotFoundError: No module named 'pymorphy2' ModuleNotFoundError:Google Colab 上没有名为“nets”的模块 - ModuleNotFoundError: No module named 'nets' on Google Colab ModuleNotFoundError:Google Colab 中没有名为“pyaudio”的模块 - ModuleNotFoundError: No module named 'pyaudio' in Google Colab 从谷歌驱动器导入谷歌 Colab 中的模块 - python - import module in Google Colab from google drive - python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM