Search code examples
pythondeep-learningdependenciesgoogle-colaboratory

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. 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'

Solution

  • I am assuming you are using this GNN-for-Text-Classification.

    Now, you have probably cloned the repository in your local system and you're running the .py files from there.

    But, a New Notebook in Colab will not have the files that you have cloned/downloaded. So, when you're doing

    !pip install utils
    

    The utils package from Pypi is getting installed which doesn't contain the functions you require.

    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. Just run the following in your 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.

    Now you can import stuff like loadWord2Vec, clean_str without any errors.

    Note that this cloning is not permanent since a new Colab instance will not keep the changes from the old one.