Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to import module in Google Colab after installing

I was trying to clone and install the Google Unrestricted adversarial examples repository following the instructions provided here. But I am unable to import the any of the modules. First I cloned the repository and changed to that directory.

!git clone https://github.com/google/unrestricted-adversarial-examples.git
cd unrestricted-adversarial-examples

Then I used the pip install command.

!pip -e install bird-or-bicycle

The installation completed without any error. However, when I try to import I get the 'module not found error'. Could anyone tell me what I am doing wrong? I tried the same commands on my PC and it works.

import bird_or_bicycle

ModuleNotFoundError: No module named 'bird_or_bicycle'

like image 611
siby Avatar asked Jan 01 '23 19:01

siby


2 Answers

I just got the solution after posting an issue to the repository. The solution was simple, all I needed to do was restart the Colab kernel (Restart Runtime option in the Runtime tab) after !pip -e install bird-or-bicycle Apparently that is required to pick up the newly installed package.

like image 191
siby Avatar answered Jan 14 '23 05:01

siby


If you look at the bird-or-bicycle docs, you see that there is a data download step required after you pip install.

If you follow the instructions there and run the following in a notebook cell, then the import will work:

!git clone https://github.com/google/unrestricted-adversarial-examples
!pip install -e unrestricted-adversarial-examples/bird-or-bicycle
!bird-or-bicycle-download
like image 21
jakevdp Avatar answered Jan 14 '23 06:01

jakevdp