You only need to look at this tutorial if you are new to Jupyter Notebooks.
This page (and its file,
01_notebook_basics.ipynb) is termed a notebook. Each notebook when opened in Jupyter, is a Python main module that can do anything a normal Python module can do. Specifically, different code sections can be executed one by one and execute all in the same Python main module.
If you view this notebook using the Online Notebook Viewer (e.g. because you clicked on the link in section Tutorials), you cannot execute the code sections in the notebook or modify the notebook. Section Executing code in the tutorials describes how to do that.
A code section can be executed by selecting it and pressing Ctrl-Enter (That is for Linux; the key combination depends on the operating system you are using).
Please execute this code section:
a = 42
And this code section:
The second code section prints the value only if you have executed the first code section before. You can see the order of code section executions in the number that is shown in brackets to the left of the code section.
You can repeat the execution of a code section that was executed earlier and you can edit code sections (by double clicking on it).
For example, you can edit the first code section above to use a different value, and execute both sections again.
The Python environment used by Jupyter for a notebook is exactly the Python environment in which the
jupyter notebook command was issued. It has the same Python version and the same Python packages installed:
import sys print(sys.version) print(sys.modules['six'])
Jupyter dynamically creates a Python module for each notebook that is open. This notebook here for example runs in the following Python module:
this_module = sys.modules[__name__] print(this_module) print('__name__ = %r' % this_module.__name__) print('__doc__ = %r' % this_module.__doc__)
Different notebooks run in different Python processes and thus have no connection between their modules.
The current working directory in a notebook is the notebooks directory (that was specified when invoking
import os print(os.getcwd())
The Python module search path within a notebook adds some Jupyter directories at the end but otherwise is the normal search path that would be available when invoking
python, i.e. it reflects the currently active Python environment. Specifically, it includes the current directory (the empty string), i.e. the notebooks directory.
import sys from pprint import pprint pprint(sys.path)