Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export Error #17

Closed
BirkhoffG opened this issue Dec 5, 2019 · 8 comments
Closed

Export Error #17

BirkhoffG opened this issue Dec 5, 2019 · 8 comments

Comments

@BirkhoffG
Copy link

Hello nbdev Team,

I try to use nbdev to develop a prototyped library, but I constantly encounter this problem when I executing notebook2script():

Converted 00_rec.ipynb.
Converted 01_ts.ipynb.
Converted 02_nlp.ipynb.

KeyError Traceback (most recent call last)
~\Anaconda3\envs\ml_env\lib\sre_parse.py in parse_template(source, pattern)
1014 try:
-> 1015 this = chr(ESCAPES[this][1])
1016 except KeyError:

KeyError: '\l'

During handling of the above exception, another exception occurred:

error Traceback (most recent call last)
in
1 from nbdev.export import notebook2script
----> 2 notebook2script()

~\Anaconda3\envs\ml_env\lib\site-packages\nbdev\export.py in notebook2script(fname, silent, to_dict)
322 else: files = glob.glob(fname)
323 d = collections.defaultdict(list) if to_dict else None
--> 324 for f in sorted(files): d = _notebook2script(f, silent=silent, to_dict=d)
325 if to_dict: return d
326 else: add_init(Config().lib_path)

~\Anaconda3\envs\ml_env\lib\site-packages\nbdev\export.py in _notebook2script(fname, silent, to_dict)
298 with open(fname_out, 'a', encoding='utf8') as f: f.write(code)
299 if f'{e}.py' not in mod.modules: mod.modules.append(f'{e}.py')
--> 300 save_nbdev_module(mod)
301
302 if not silent: print(f"Converted {fname.name}.")

~\Anaconda3\envs\ml_env\lib\site-packages\nbdev\export.py in save_nbdev_module(mod)
259 code = _re_index_idx.sub("index = {"+ t +"}", code)
260 t = ',\n '.join([f'"{f}"' for f in mod.modules])
--> 261 code = _re_index_mod.sub(f"modules = [{t}]", code)
262 with open(fname, 'w') as f: f.write(code)
263

~\Anaconda3\envs\ml_env\lib\re.py in _subx(pattern, template)
307 def _subx(pattern, template):
308 # internal: Pattern.sub/subn implementation helper
--> 309 template = _compile_repl(template, pattern)
310 if not template[0] and len(template[1]) == 1:
311 # literal replacement

~\Anaconda3\envs\ml_env\lib\re.py in _compile_repl(repl, pattern)
298 def _compile_repl(repl, pattern):
299 # internal: compile replacement pattern
--> 300 return sre_parse.parse_template(repl, pattern)
301
302 def _expand(pattern, match, template):

~\Anaconda3\envs\ml_env\lib\sre_parse.py in parse_template(source, pattern)
1016 except KeyError:
1017 if c in ASCIILETTERS:
-> 1018 raise s.error('bad escape %s' % this, len(this))
1019 lappend(this)
1020 else:

error: bad escape \l at position 18

`
I have no idea where the code crash, but seems like there is some problems in my 03a_*.ipynb notebook since after I delete this notebook, everything works well. But after recreating this notebook and executing a few exports, this problem occurs again.

I am using Windows Anaconda, Jupyter Notebook.

Best

@sgugger
Copy link

sgugger commented Dec 5, 2019

It seems there is a special character in your notebook name (from the stack trace). Is it really named 03a_*.ipynb? That might be the source of the problem.

@BirkhoffG
Copy link
Author

It seems there is a special character in your notebook name (from the stack trace). Is it really named 03a_*.ipynb? That might be the source of the problem.

My notebook's name is 03a_module_layers.ipynb.

@daviddemeij
Copy link

Maybe something goes wrong because of the backslashes used in Windows paths? Or has nbdev been tested on Windows already?

@sgugger
Copy link

sgugger commented Jan 8, 2020

No, this is not that. nbdev works on Windows and has been tested, with the exception of the diff command however (this will be fixed when I have time to rewrite it).

@hamelsmu
Copy link
Member

@BirkhoffG can you supply a public version of this notebook ( or a stripped-down version thereof )? I would like to see if I can reproduce this error!

@hamelsmu
Copy link
Member

hamelsmu commented Jan 30, 2020

@BirkhoffG this appears to definitely be something in your notebook. For example, if I open 00_export.ipynb and run the following cells

# copy existing notebook for testing
! cp 99_search.ipynb 03a_module_layers.ipynb
notebook2script('03a_module_layers.ipynb')

I don't see your error. Hope that helps

@sgugger
Copy link

sgugger commented Feb 3, 2020

I'm closing the issue since we can't reproduce and fix, please do not hesitate to reopen with an example of the bug (preferably with the notebook file that fails).

@sgugger sgugger closed this as completed Feb 3, 2020
@Tom-TBT
Copy link

Tom-TBT commented Feb 27, 2020

Hello,
I had a similar issue, I'm working with windows. The notebook2script() worked fine until I made submodules. After I got the error, I created new modules that aren't nested and they could be exported fine, so it seems that notebook2script() fails specifically the submodules.

Then I updated nbdev from 0.1.6 to the latest to date 0.2.12 and it worked fine. Hope it can help someone.

jph00 pushed a commit that referenced this issue Jul 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants