简体   繁体   English

Google Colab 中没有名为“utils.utils”的模块

[英]No module named 'utils.utils' in Google Colab

I'm trying to run this python code in Google Colab and I always get this error that the utils module is not installed or does not exist yet I've ran !pip install utils and the still the same issue.我正在尝试在 Google Colab 中运行此 python 代码,但我总是收到此错误,即 utils 模块未安装或尚不存在,但我已经运行了 !pip install utils 并且仍然是同样的问题。 I've tried running it on my computer and it works without issues but I can't actually run it due to limited resources of my pc.我试过在我的电脑上运行它,它可以正常工作,但由于我的电脑资源有限,我实际上无法运行它。

anyway anyone has a solution for this ?无论如何,有人对此有解决方案吗?

Traceback (most recent call last):
  File "/content/GNN-for-text-classification/preprocess/build_graph.py", line 15, in <module>
    from utils.utils import loadWord2Vec, clean_str
ModuleNotFoundError: No module named 'utils.utils'

I am assuming you are using this GNN-for-Text-Classification .我假设您正在使用这个GNN-for-Text-Classification

Now, you have probably cloned the repository in your local system and you're running the .py files from there.现在,您可能已经在本地系统中克隆了存储库,并且正在从那里运行.py文件。

But, a New Notebook in Colab will not have the files that you have cloned/downloaded.但是,Colab 中的新笔记本不会包含您克隆/下载的文件。 So, when you're doing所以,当你在做

!pip install utils

The utils package from Pypi is getting installed which doesn't contain the functions you require. Pypiutils包正在安装,它不包含您需要的功能。

What you need is actually the utils module from GNN-for-Text-Classification , for which you'll need to clone and cd into the folder in Colab itself.您需要的实际上是来自GNN-for-Text-Classificationutils模块,为此您需要克隆并cd到 Colab 本身的文件夹中。 Just run the following in your Colab Notebook:只需在 Colab Notebook 中运行以下命令:

!git clone https://github.com/zshicode/GNN-for-text-classification.git
%cd GNN-for-text-classification/
%ls

This will clone the repo, cd into the folder and view the contents where you will be able to find the utils module that you need.这会将 repo、cd 克隆到文件夹中并查看内容,您将能够在其中找到所需的utils模块。

Now you can import stuff like loadWord2Vec, clean_str without any errors.现在您可以毫无错误地导入诸如loadWord2Vec, clean_str类的内容。

Note that this cloning is not permanent since a new Colab instance will not keep the changes from the old one.请注意,此克隆不是永久性的,因为新的 Colab 实例不会保留旧实例的更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM