Closed ashutoshbondre closed 6 years ago
Oooh, I'm liking this spec file and script. Great approach for testing our own compliance.
Hey quick question, how can I run the code cell using python command? Like I know in the notebook you can do shift+enter, but if I don't want to manually do that, and just run the code cells using my script & get the output of the code cells in the notebook, what is the command / syntax for that? If at all that's possible. Thanks.
@ashutoshbondre Where are you running it from? If you can use nbconvert
the Execute preprocessor probably does what you want: http://nbconvert.readthedocs.io/en/latest/execute_api.html
And if you want to do on individual cells directly, I'd recommend looking at the internals of the Execute preprocessor, specifically the preprocess_cell
or the run_cell
commands. I wouldn't use that code verbatim (it makes more sense in the nbconvert context) but it should get you a good chunk of the way there.
Btw, just looked and was there a reason you used a python2 kernel? If not please switch to using python3? I anticipate that we'll eventually run into unicode bugs in this spec code otherwise.
No reason. I will change that, and thanks for the help.
On Jun 14, 2017 3:17 PM, "M Pacer" notifications@github.com wrote:
Btw, just looked and was there a reason you used a python2 kernel? If not please switch to using python3? I anticipate that we'll eventually run into unicode bugs in this spec code otherwise.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
Looking at what you have, what I'd do is something like:
# ⋮ your imports
from nbconvert import ExecutePreprocessor
kernel_name = 'python3' # set it programmatically so that you only need to change it in one place
display_name = 'Python 3'
output_path = '/Users/ashu/github/ans.ipynb' # probably want to use a relative path?
timeout_amount = 60 # none of these should take too long
metadata = {'kernelspec': {
'name': your_kernel_name
'display_name': display_name
}} # this might need to be populated with more valid metadata, but I'm not sure which metadata you'll actually need.
format_version = 4.3
# ⋮ this is where your spec reading and cell writing would happen
executor = ExecutePreprocessor(timeout=60, kernel_name=your_kernel_name)
executor.preprocess(nb, metadata)
nbformat.write(nb,"/Users/ashu/github/ans.ipynb", format_version)
Hope that helps!
@mpacer Thanks for the review, did most of the changes. Also ExecutePreprocessor did what I wanted.
One reason I used python 2 kernel was because that was the default one I had, I am having problems with executing the code in python3. I set up a different environment in python 3 using "conda create" command, but when I execute the code there,it doesn't even recognize nbformat. Says "no module named nbformat" .
Currently I am working on Python 2.7.13. Can you tell me, what can I do here, to switch to the right environment. I am pretty sure, I am just missing some minute detail. Thanks
You would need to run pip install nbformat
to install that package in the
2.7 environment, making sure that the right version of pip/python is in
your path. Python packages have to be installed separately in each python
version's site-packages dir.
On Wed, Jun 14, 2017 at 5:02 PM, Ashutosh Bondre notifications@github.com wrote:
@mpacer https://github.com/mpacer Thanks for the review, did most of the changes. Also ExecutePreprocessor did what I wanted.
One reason I used python 2 kernel was because that was the default one I had, I am having problems with executing the code in python3. I set up a different environment in python 3 using "conda create" command, but when I execute the code there,it doesn't even recognize nbformat. Says "no module named nbformat" .
Currently I am working on Python 2.7.13. Can you tell me, what can I do here, to switch to the right environment. I am pretty sure, I am just missing some minute detail. Thanks
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jupyter/jupyter_markdown/pull/1#issuecomment-308591318, or mute the thread https://github.com/notifications/unsubscribe-auth/AABr0BaYzdmzIN1TUVhPkl-AaKy_T7pgks5sEHSTgaJpZM4N39u1 .
-- Brian E. Granger Associate Professor of Physics and Data Science Cal Poly State University, San Luis Obispo @ellisonbg on Twitter and GitHub bgranger@calpoly.edu and ellisonbg@gmail.com
You need to switch into that environment and specifically install nbformat, notebook, lab, &c. to that environment. To make it easy you could use conda install but you should also be able to use pip if you want. If you go that route & run into trouble let me know.
Then, you need to install the kernel relative to that environment, which you can install by following instructions here: http://ipython.readthedocs.io/en/stable/install/kernel_install.html
If you want access to that kernel in all your environments use
--sys-prefix
when installing.
Then it should work.
On Wed, Jun 14, 2017 at 17:02 Ashutosh Bondre notifications@github.com wrote:
@mpacer https://github.com/mpacer Thanks for the review, did most of the changes. Also ExecutePreprocessor did what I wanted.
One reason I used python 2 kernel was because that was the default one I had, I am having problems with executing the code in python3. I set up a different environment in python 3 using "conda create" command, but when I execute the code there,it doesn't even recognize nbformat. Says "no module named nbformat" .
Currently I am working on Python 2.7.13. Can you tell me, what can I do here, to switch to the right environment. I am pretty sure, I am just missing some minute detail. Thanks
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/jupyter/jupyter_markdown/pull/1#issuecomment-308591318, or mute the thread https://github.com/notifications/unsubscribe-auth/ACXg6MmWwnuMzvQnzG5b8tmyThTT5Gsdks5sEHSTgaJpZM4N39u1 .
Ready for review: Hi, I did all the necessary changes, added relative paths as well. The script now takes json data of any size & creates a number of notebooks, each with 100 examples. So in our case we have 643 entires, so it creates 7 notebooks, six with size 100 & seventh with 43 entries. Notebooks are named nb1, nb2, nb3, etc. on creation. Each notebook has 3 cells for each entry, which are:
Thanks, Ashutosh
All made with python3 kernel.
I'd like to go ahead and assume that the requested changes were made and this is ready to go.
Added 3 files: