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)
- [idea]support for deno or other languages(simple directive is enough) HOT 1
- fastai/workflows/quarto-ghp@master failing and reporting "no module named 'pandas' HOT 1
- nbdev_install_quarto doesn't work with Windows 10 system HOT 1
- Blog post broken links
- Add code folding for `exports`
- Move `exports` source after the show_doc
- Add magic `__` symbols to `show_doc` output
- Remove boxes since they broke ToC
- UnboundLocalError: cannot access local variable '_TEMPLATE' where it is not associated with a value HOT 2
- Auto-trust notebooks after `nbdev_clean`
- add `nbdev_requirements`
- Direct invocation of setup.py deprecated when uploading package to PyPi
- nbdev_docs doesn't provide location of error
- Doc error: line number is `None`
- matplotlib outputs text representation instead of figure
- Add support for copying output files to website
- Python 3.12 No module named 'pkg_resources' HOT 3
- nbdev_install_quarto does not work in Windows HOT 1
- Error in index.ipynb after setting up nbdev-hello-world repo on a new Windows machine
- Question: How to make **multi-language** documentation for a nbdev project?
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.