[英]How to import notebooks .py inside the Google Colab?
I want to use some functions that are contained in other python modules/notebooks ( .py
) in a google colab notebook.我想在 google colab notebook 中使用其他 python 模块/笔记本(
.py
)中包含的一些功能。
With the google colab notebook open, I went to index >> files >> upload and uploaded the file EOS.py
.打开 google colab notebook 后,我转到 index >> files >> upload 并上传文件
EOS.py
。 However, when I do import EOS
or from EOS import set_eos
it gives an error.但是,当我
import EOS
或from EOS import set_eos
时,会出现错误。 What should I change so that the call of a mudlo or external function of a mutale is correct?我应该更改什么以便 mutale 的 mutale 或外部 function 的调用是正确的?
You can save it first, then import it.您可以先保存,然后再导入。
from google.colab import files
src = list(files.upload().values())[0]
open('EOS.py','wb').write(src)
import mylib
Now you can upload easily by现在您可以通过以下方式轻松上传
If you don't want to upload every time, you can store it in S3 and mount it to Colab, as shown in this https://gist.github.com/korakot/e28ea5269129b70f220fe5e8d065b446如果不想每次都上传,可以存储在S3中,挂载到Colab中,如下图https://gist.github.com/korakot/e28ea5269129b70f220fe5db464
Now that you can mount your Google Drive automatically.现在您可以自动挂载您的 Google 云端硬盘了。 It is easier to just copy it from Drive than upload it.
从云端硬盘复制它比上传它更容易。
EOS.py
in your Drive EOS.py
存储在您的驱动器中Files
viewFiles
视图Mount Drive
then Connect to Google Drive
Mount Drive
然后Connect to Google Drive
.cp drive/MyDrive/EOS.py .
.cp drive/MyDrive/EOS.py .
import EOS
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.