!nbdev_build_lib ImportError: cannot import name '_documents'... in Colab

Hi there,

When I want to pack my code developed in Colab into my package, I did

!nbdev_build_lib

It returned this error message:
Traceback (most recent call last):
File “/usr/local/bin/nbdev_build_lib”, line 5, in
from nbdev.export2html import nbdev_build_lib
File “/usr/local/lib/python3.7/dist-packages/nbdev/export2html.py”, line 15, in
from .showdoc import *
File “/usr/local/lib/python3.7/dist-packages/nbdev/showdoc.py”, line 12, in
from fastcore.docments import _docments, isclass, _clean_comment, _tokens, _param_locs, _get_comment
ImportError: cannot import name ‘_docments’ from ‘fastcore.docments’ (/usr/local/lib/python3.7/dist-packages/fastcore/docments.py)

Here is how it looks like:

2 Likes

Hi @wjlgatech welcome to the forum!

That issue actually happens to me on my local machine when I have nbdev installed globally but running it within a virtual environment.
I’m not too familiar with Colab but, did you create a venv there? (e.g. by running python -m venv .venv)?

If so, try to uninstall nbdev from the global colab modules:

  1. If you’re in the venv, deactivate.
  2. pip uninstall nbdev.
  3. Activate the venv again
  4. pip install nbdev.

Hopefully that helps.

In case you missed it, there are a few extra steps for Colab at nbdev in colab tutorial | nbdev_colab_helper
Also, sounds like others had issues too Using Nbdev with Google Colab - #21 by Mukei

Happy coding! :slight_smile:

1 Like

Run pip install fastcore -U and it should fix it

2 Likes

Fantastic! The trick works. Can you please explain why?

1 Like

Awesome @DiogoSnows, a win for notebook-er on local machine!

2 Likes

Because I’ve seen this exact error message before while keeping an eye on the nbprocess development :wink:

2 Likes

Much better solution :grinning:

I am having the same error in paperspace.
Tried

pip install fastcore -U

but the problem was not fixed…
Any other ideas?

1 Like

Did you also restart the notebook?

1 Like

Yes, restarted notebook, same problem…

Can you post your versions of nbdev and fastcore?

I upgraded to fastai 2.7.4 and the problem went away… Thanks.

1 Like