Unable to import module in Google Colab after installing

一笑奈何 提交于 2019-12-10 09:47:34

问题


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'


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/52483662/unable-to-import-module-in-google-colab-after-installing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!