从Google驱动器在Google Colab中导入模块-python [英] import module in Google Colab from google drive - python

查看:134
本文介绍了从Google驱动器在Google Colab中导入模块-python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Google驱动器导入ipynb文件时遇到问题.我尝试过以下解决方案:

谢谢您提前回答

解决方案

来源

第1步首先,您必须在google colab中挂载google驱动器:如下所示,您在Google驱动器上的文件是Google colab中的导入文件/包.

 #在google colab中挂载您的google驱动器从google.colab导入驱动器drive.mount('/content/drive') 

第2步其次,使用sys将目录插入到您的python路径:

 #插入目录导入系统sys.path.insert(0,'/content/drive/我的云端硬盘/ColabNotebooks') 

第3步现在,您可以从该目录导入模块或文件.

 #导入模块或文件导入my_module 

I have a problem with import ipynb file from my google drive. I've tried solutions from: Importing .py files in Google Colab How to import custom modules in google colab?

but does not work for me.

# COLAB
from google.colab import files
from google.colab import drive
# SYS
import sys
# IPYNB
!pip install import-ipynb
import import_ipynb
# UTIL
import importlib.util

I've tried something like this:

drive.mount('/content/drive')
sys.path.append('/content/drive/My Drive/Colab Notebooks/')
import Data_Preparation_Library

Or this:

!cp "/content/drive/My Drive/Colab Notebooks/Data_Preparation_Library.ipynb"
import Data_Preparation_Library

Here is how my gdrive structure looks like:

Thank You for answers in advance

解决方案

SOURCE

Step 1 Primarily, you must Mount your google drive in google colab: Code to below, your files on your google drive is import files/packages inside a google colab.

# Mount your google drive in google colab
from google.colab import drive
drive.mount('/content/drive')

Step 2 Secondly, insert the directory to your python path using sys:

# Insert the directory
import sys
sys.path.insert(0,’/content/drive/My Drive/ColabNotebooks’)

Step 3 Now, you can be able to import your module or file stuff from that directory.

# Import your module or file
import my_module

这篇关于从Google驱动器在Google Colab中导入模块-python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆