Submodule import not working on Google Colab

守給你的承諾、 提交于 2019-12-24 20:32:39

问题


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:


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.



来源:https://stackoverflow.com/questions/54490717/submodule-import-not-working-on-google-colab

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