AnswerDotAI / AnswerDotAI/nbdev

import_module fails when running nbdev_update in new nbdev project.

Open
#1,238 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
5.3k
Forks
513
Avg merge
2d 30m
Merged PRs (30d)
8

Description

This is caused when running `nbdev_update` in a new project called nbdev-blog.

```python
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[4], line 1
----> 1 midx = import_module(f'{get_config().lib_name}._modidx')

File /usr/lib/python3.10/importlib/__init__.py:126, in import_module(name, package)
124 break
125 level += 1
--> 126 return _bootstrap._gcd_import(name[level:], package, level)

File :1050, in _gcd_import(name, package, level)

File :1027, in _find_and_load(name, import_)

File :992, in _find_and_load_unlocked(name, import_)

File :241, in _call_with_frames_removed(f, *args, **kwds)

File :1050, in _gcd_import(name, package, level)

File :1027, in _find_and_load(name, import_)

File :1004, in _find_and_load_unlocked(name, import_)

ModuleNotFoundError: No module named 'nbdev-blog'
```

Reproduced in REPL:
```python
from importlib import import_module

from nbdev.config import *

cfg = get_config()

midx = import_module(f'{get_config().lib_name}._modidx')
```

This can be fixed in 1 of 2 ways:

1. Change the settings.ini default to change dashes to underscores in the default lib_name
```
### Python library ###
repo = nbdev-blog
lib_name = %(repo)s
```

I fixed this issue locally by changing the above to:
```
### Python library ###
repo = nbdev-blog
lib_name = nbdev_blog
```

2. Change lib_name to lib_path in the sync.

This line: https://github.com/fastai/nbdev/blob/46d05d40fb8bfd1f6466f3daabc1fcf300a73fde/nbdev/sync.py#L33

Could be changed to:

`midx = import_module(f'{get_config().lib_path}._modidx')`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.