mel*_*olo 7 python google-colaboratory
我想DataProcesser从load_data.pypython 文件运行一个函数,该文件可以在我的 google 驱动器路径中找到gdrive/My\ Drive/Colab\ Notebooks/CODEX/source/。
from google.colab import drive
drive.mount('/content/gdrive')
# Custom functions/classes
path_to_module = 'gdrive/My\ Drive/Colab\ Notebooks/CODEX/source/' # Path where all the .py files are, relative to the notebook folder
sys.path.append(path_to_module)
from load_data import DataProcesser
Run Code Online (Sandbox Code Playgroud)
追溯:
> --------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call
> last) <ipython-input-30-066e93c75b7d> in <module>()
> 20 path_to_module = 'gdrive/My\ Drive/Colab\ Notebooks/CODEX/source/' # Path where all the .py files are, relative
> to the notebook folder
> 21 sys.path.append(path_to_module)
> ---> 22 from load_data import DataProcesser
> 23 from train_utils import even_intervals
> 24 from models import *
>
> ModuleNotFoundError: No module named 'load_data'
>
> --------------------------------------------------------------------------- NOTE: If your import is failing due to a missing package, you can
> manually install dependencies using either !pip or !apt.
>
> To view examples of installing some common dependencies, click the
> "Open Examples" button below.
> -------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
您可能不需要转义字符串中的空格path_to_module,但 Colab 看到的路径可能不同。如果您展开filesColab 中的选项卡,您可以导航到 Google Drive 中的文件。然后您可以右键单击您想要的文件或文件夹并执行操作Copy path。然后您可以将其粘贴到定义的单元格中path_to_module。
可以说,它对我有用;但我的路径 ( .../tmp) 会与你的不同。
from google.colab import drive
drive.mount('/content/gdrive')
import sys
path_to_module = '/content/gdrive/MyDrive/tmp'
sys.path.append(path_to_module)
from mypy import myfunc
Run Code Online (Sandbox Code Playgroud)
我导航到该tmp文件夹并复制属性,然后将其粘贴到代码中。
| 归档时间: |
|
| 查看次数: |
13872 次 |
| 最近记录: |