the most rudimentary ipython notebook questions from a first-time user: - python

Been using the safe and easy confines of PyCharm for a bit now, but I'm trying to get more familiar with using a text editor and the terminal together, so I've forced myself to start using iPython Notebook and Emacs. Aaaaand I have some really dumb questions.
after firing up ipython notebook from terminal with the command 'ipython notebook', it pops up on my browser and lets me code. but can i not use terminal while it's connected to ipython notebook server?
after writing my code in ipython notebook, i'm left with a something.ipynb file. How do I run this file from terminal? If it was a .py file, i know i could execute it by tying python something.py from the command line; but it doesn't work if i type python something.ipynb in the command line. And of course, I assume I hit Control-C to quit out of the running server in terminal first? or do I run the command without quitting that? Or am i doomed to test it in iPython and then copy and paste it to a different txt editor like Emacs and save it in a .py file to run it?
what good is the .ipynb file if i can't run it in terminal or outside the iPython Notebook browser? Could I get my code in a .py from iPython Notebook if I wanted to? (i assume I'll be able to easily run it in terminal by tying something.py then)
thanks in advance. I'm still very much trying to figure out how to use this thing and there aren't many answers out there for questions this elementary.

Yes, you can not use the same terminal. Solutions: open another terminal or run ipython notebook inside screen. If you use Windows you might want to take a look into this question
Notebook documents (ipynb files) can be converted to a range of static formats including LaTeX, HTML, PDF and Python. Read more about converting notebooks in manual
Notebooks are great, because you can show other people your interactive sessions accompanied with text, which may have rich formatting. And if someone can run notebook server he can easily reproduce your computations and maybe modify them. Check out awesome notebook on traveling salesperson problem by Peter Norvig as an example of what you can do with ipynb. Or this notebook. More examples are available here

You can run your IPython notebook process in background.
On Unix platforms you can perform that with (note the leading &):
ipython notebook &
Or after a "normal" run, hit [Control+z] and run the bg command
(some lecture).
you can convert .ipynb file into .py file using nbconvert
with Ipython notebook 2.x (some lecture):
ipython nbconvert --to python mynotebook.ipynb
with Ipython notebook 3.x (some lecture):
ipython nbconvert --to script mynotebook.ipynb
.ipynb contains your script AND results AND formatted text.
You can compare it to a literate script (but using "machine programming language").

Related

How to debug Jupyter Notebook profile_default/startup File?

I am placing a .py file in Jupyter Notebook profile_default/startup folder. It has some problems, I want to debug and see the logs. Is there any way I see the output or logs generated by that file. I am on windows 10. There are a few methods .py file. I am using keyboard module to generate a hotkey whenever the notebook starts. It isn't working for me. Please suggest a good way to at least debug that file. My ipykernel is 5.3.4 and ipython 7.16.1
The easiest way I've found so far is to fire up ipython from your console.
Assuming the error is not specific to how Jupyter starts the kernel, you will see the error with the stacktrace before the ipython shell starts.
If the error is specific to jupyter kernel, use jupyter kernel. It will start the kernel you specify, and drop a log line if there's an error.

Showing output both with Jupyter notebook and in python interactive at same time?

I imagine this question is rather silly.
I'm using VS code and Jupyter notebooks within it. Is it possible to have the output sent to the interactive python interpreter instead/at the same time as the output beneath the Jupyter notebook cells? I tried searching, google but failed.
The answer in short is unfortunately 'no'. The Interactive window can be used with the #%% magic line or using the 'Jupiter.execSelectionInteractive' command (⇧ + ↩ on Mac). However, the later is not available in a notebook, only in .py files.

Preview Jupyter Notebooks in Ubuntu

Peeking at Jupyter notebooks is a long process, need to cd to the file location and need to run jupyter notebook to start the server and get things done, but I don't need to edit or work with it. Is there any other possible way to just take a look at notebooks quickly?
Looking for the Linux equivalent of this tuxu/nbviewer
PS: Already know about a Firefox extension but it is broken now.
.ipynb(s) cannot be previewed, instead if you convert your notebook to html, it can be previewed right away, use jupyter nbconvert --to html yournotebook.ipynb and preview it with a double click. You can write your own code to automate this since you are using python, or you can install this nb-viewer which basically lets you open .ipynb(s) in your linux machine with a double-click.

How to save the python scripts made on Python console in Pycharm?

I have been writing scripts in Python console provided in Pycharm but now I need to save them on my desktop and run them at some later point. I can not happen to find any option to do so for the console scripts.
I don't think there is a way to save the contents of a console session within PyCharm (or any other editor that I know of). As #daladier pointed out in the comments, though, iPython may be what you are looking for. Using Jupyter Notebooks which are based on iPython you can create interactive cells in notebooks that behave similar to the console.

IPython notebook does not capture all console output

within my code I use a Python package that calls external programs which write their output to the same console that IPython is running in. If I now run the same code from an IPython notebook, the output is not written to the notebook output cells, but into the console that the IPython notebook server is running in.
Do you know if it is possible to capture this output somehow, and then display it within the IPython notebook? I'm on Xubuntu 14.04, by the way.
Thank you very much for your help!
This gives you nice and comprehensive description of your problem and potential solutions. You need to try it out for yourself with your specific setup.

Categories