Comments (9)
The library doesn't support having two different default_exp
values. To export a cell in a different module than the default you set, set the flag # export module_name
. If you want to export one given to cell to two different modules, you will need to duplicate it with two different export flags for now.
Hope this helps solve your issue!
from nbdev.
ult_exp
values. To export a cell in a different module than the default you set, set the flag# export module_name
. If you want to export one given to cell to two different modules, you will need to duplicate it with two different export flags for now.
Hope this helps solve your issue!
Thanks for the reply, yes I realize there is # export module_name
But this will run in to error when nbdev_build_lib
,
AttributeError: 'NoneType' object has no attribute 'start'
I pip installed nbdev from the master branch of git source on 2020-02-06, using source code of this committed version
from nbdev.
What is the exact comment you type, so that I have a reproducer?
from nbdev.
Reproduce the No such file or directory
error
eg. the dummy notebook I was trying to convert,
I ran nbdev_build_lib
, the following is the error:
Traceback (most recent call last):
File "/Users/salvor/anaconda3/bin/nbdev_build_lib", line 8, in <module>
sys.exit(nbdev_build_lib())
File "/Users/salvor/.local/lib/python3.7/site-packages/fastscript/core.py", line 73, in _f
func(**args.__dict__)
File "/Users/salvor/.local/lib/python3.7/site-packages/nbdev/cli.py", line 22, in nbdev_build_lib
notebook2script(fname=fname)
File "/Users/salvor/.local/lib/python3.7/site-packages/nbdev/export.py", line 371, in notebook2script
for f in sorted(files): d = _notebook2script(f, silent=silent, to_dict=d)
File "/Users/salvor/.local/lib/python3.7/site-packages/nbdev/export.py", line 310, in _notebook2script
if to_dict is None: _add2add(fname_out, [f"'{f}'" for f in names if '.' not in f and len(f) > 0] + extra)
File "/Users/salvor/.local/lib/python3.7/site-packages/nbdev/export.py", line 180, in _add2add
with open(fname, 'r', encoding='utf8') as f: text = f.read()
FileNotFoundError: [Errno 2] No such file or directory: '/Users/salvor/github/forgebox/forgebox/different_file.py
However, the test_nbdev.py was built successfully.
Try the empty file
I guess the pre-existence is important for different_file.py
, so I created such empty file, run nbdev_build_lib
, following the new error
Traceback (most recent call last):
File "/Users/salvor/anaconda3/bin/nbdev_build_lib", line 8, in <module>
sys.exit(nbdev_build_lib())
File "/Users/salvor/.local/lib/python3.7/site-packages/fastscript/core.py", line 73, in _f
func(**args.__dict__)
File "/Users/salvor/.local/lib/python3.7/site-packages/nbdev/cli.py", line 22, in nbdev_build_lib
notebook2script(fname=fname)
File "/Users/salvor/.local/lib/python3.7/site-packages/nbdev/export.py", line 371, in notebook2script
for f in sorted(files): d = _notebook2script(f, silent=silent, to_dict=d)
File "/Users/salvor/.local/lib/python3.7/site-packages/nbdev/export.py", line 310, in _notebook2script
if to_dict is None: _add2add(fname_out, [f"'{f}'" for f in names if '.' not in f and len(f) > 0] + extra)
File "/Users/salvor/.local/lib/python3.7/site-packages/nbdev/export.py", line 183, in _add2add
start,end = re_all.start(),re_all.end()
AttributeError: 'NoneType' object has no attribute 'start'
When using another notebook's default_exp
Okay, so the empty one won't suffice, so I created another notebook , solely in purpose to create a fully fledged py file.
This time, nbdev_build_lib
turns out fine. all py file are in place
But nbdev_build_docs
will have this error
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-3-e86c8b69e1ff> in <module>
----> 1 show_doc(different_file_func, default_cls_level=2)
NameError: name 'different_file_func' is not defined
from nbdev.
You have to put a number of your notebooks since they need to run in a certain order during nbdev_build_lib:
- the notebook creating different_file.py has to run first so that the module exists
- then the notebook creating test_file.py can run and add its function different_file_func to different_file
This is why all notebooks in our nbdev-generated packages begin with digits.
from nbdev.
yes I tried, the correct order can generate py files correctly. yes
but nbdev_build_DOCS will have error NameError: name 'different_file_func' is not defined
from nbdev.
I need more than this as I can't reproduce what you are saying. Please share a whole folder with the numbered notebooks, exported library where the error appears.
from nbdev.
I added the following 2 files into a nbdev template repo
- 01_create_different.ipynb, this will create a file using
#default_exp different_file
- 02test_nbdev.ipynb, inserting a function to
different_file.py
Then in this step, everything's okay 👌
$ nbdev_build_lib
Then in this step for docs, error ❌
$ nbdev_build_docs
converting: /Users/salvor/github/nbdev_test/00_core.ipynb
converting: /Users/salvor/github/nbdev_test/02test_nbdev.ipynb
converting: /Users/salvor/github/nbdev_test/index.ipynb
converting: /Users/salvor/github/nbdev_test/01_create_different.ipynb
An error occurred while executing the following cell:
------------------
show_doc(different_file_func, default_cls_level=2)
------------------
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-3-e86c8b69e1ff> in <module>
----> 1 show_doc(different_file_func, default_cls_level=2)
NameError: name 'different_file_func' is not defined
NameError: name 'different_file_func' is not defined
Traceback (most recent call last):
File "/Users/salvor/anaconda3/bin/nbdev_build_docs", line 8, in <module>
sys.exit(nbdev_build_docs())
File "/Users/salvor/.local/lib/python3.7/site-packages/fastscript/core.py", line 73, in _f
func(**args.__dict__)
File "/Users/salvor/.local/lib/python3.7/site-packages/nbdev/cli.py", line 164, in nbdev_build_docs
notebook2html(fname=fname, force_all=force_all, n_workers=n_workers)
File "/Users/salvor/.local/lib/python3.7/site-packages/nbdev/export2html.py", line 412, in notebook2html
raise Exception(msg + '\n'.join([f.name for p,f in zip(passed,files) if not p]))
Exception: Conversion failed on the following:
02test_nbdev.ipynb
from nbdev.
I encountered the same issue when trying to generate two (or more) .py files from single notebook - I thought it was a good idea to place function definitions and other code into different modules.
So even when I bypassed No such file or directory
error (but its behavior is still unclear sometimes)
I noticed that modules created by # export <module>
expression expand with each run of nbdev_build_lib
which duplicates code and thus quickly makes these modules become messy if one runs nbdev_build_lib
or notebook2script
often (e.g. as a part of iterative process)
So I found that feature for cleaning lib_path
might be useful as an argument for notebook2script
to re-create all the modules along with _ndbev.py
.
It also occured to me that a little more explicit behavior of creating modules might be useful - I believe it could be achieved by calling create_mod_file
func inside _notebook2script
when iterating over cells
in case module in # export <module>
still wasn't created during conversion.
from nbdev.
Related Issues (20)
- `black` is not found when `nbdev_export` is run in pre-commit hook
- How to document a module and or constants? HOT 1
- `nbdev_test` fails to run tests when preceded by `langchain.embeddings.HuggingFaceEmbeddings` HOT 1
- keyword only '*' does not work with documentation
- nbdev_test having issues because of Python caching modules
- [Question] Can I install nbdev in a virtual env with only ipykernel instead of jupyter? HOT 3
- In settings.ini `min_python = 3.11` causes problem with pip install -e '.[dev]' HOT 2
- Enum renders kind of weird HOT 1
- omitting author-email from settings.ini HOT 1
- No way to specify `conda_build_config.yaml` from `settings.ini`
- [Question] How to change the licence from Apache-2.0 to GPL-3.0-only ? HOT 1
- Remove `nbdev_deploy` from the documentation website
- ImportError: cannot import name 'uname' from 'os' [Windows] HOT 3
- `nbdev_docs` raises `FileNotFoundError` when looking for `_proc/docs` HOT 2
- No documentation rendered for return type when function has no arguments
- No configuration options for `meta.yml` used by `nbdev_conda`, immediate fix required.
- nbdev_import HOT 2
- `proc_nbs` does not make use of its arguments `file_glob` and `file_re`
- Use of `pkg_resources` is deprecated
- Nested `lib_path` values break module -> notebook sync
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nbdev.