Submodule import not working on Google Colab

2019-08-25 08:43发布

I have a package called boo which I install on google colab from a github repository. The installation process looks fine and results in success message Successfully installed boo-0.1. However import boo fails on first internal import.

I replicated the same installation steps in a local virtual environment and package worked, but not on collab.

Here are my steps and error trace:

!rm -rf sandbox
!git clone https://github.com/ru-corporate/sandbox.git
!pip install -r sandbox/requirements.txt 
!pip install sandbox/.

Alternatively, I tried

!pip install git+https://github.com/ru-corporate/sandbox.git@master

The error trace is:

ModuleNotFoundError                       Traceback (most recent call last)

<ipython-input-7-fc0b1d036b35> in <module>()
----> 1 import boo

/usr/local/lib/python3.6/dist-packages/boo/__init__.py in <module>()
----> 1 from boo.boo import download, build, read_dataframe, files
      2 from boo.views.whatis import whatis

/usr/local/lib/python3.6/dist-packages/boo/boo.py in <module>()
      3 from tqdm import tqdm
      4 
----> 5 from boo.file.download import curl

Basically, from root __init__.py the import goes to root boo.py and stumbles upon finding boo/file/download.py.

How do I make this package work on collab?

1条回答
趁早两清
2楼-- · 2019-08-25 09:22

I could fix the subpackage behavior by editing setup.py as suggested here:

  # ...
  packages=setuptools.find_packages()
  # ...

Somehow Colab is more restrictive on this parameter than local installation.

查看更多
登录 后发表回答