I quote Min RK
IPython developer:
"When you start plain terminal IPython, the shell is created in the same process. That means that IPython executes in the same context as the changes you have made to sys.path, so the changes have the desired effect. In the notebook, only the notebook server exists in that context. Kernels are started as subprocesses, and thus recreate sys.path at startup, following the standard procedure for a Python process, and do not inherit any runtime changes to sys.path that may have happened in parent processes." (https://github.com/ipython/ipython/issues/5420)
My Solution
Thus the only way to pass the path to notebook is via PYTHONPATH
.
My workaround by now is to set os.environ['PYTHONPATH'] = ':'.join(sys.path)
in the script. With this you don't need to mess the PYTHONPATH (if any) of your system and you make sure that all the necessary paths will be passed to the kernel.
The os.environ
is passed as env
argument of Popen
to the subprocess in launch_kernel
(.../ipython-1.2.1-py2.7.egg/IPython/kernel/launcher.py
).
If you need to use ipython's notebook and want buildout to generate the script, add the following to your buildout (e.g. in .../Plone-4.3.2/zeocluster/develop.cfg
)
parts +=
...
ipzopenb
...
[ipzopenb]
recipe = zc.recipe.egg
eggs =
ipython
pyzmq
tornado
Jinja2
#following for nbconvert
Pygments
Sphinx
${client2:eggs}
initialization =
import sys, os
os.environ["INSTANCE_HOME"] = "${client2:location}"
os.environ['PYTHONPATH'] = ':'.join(sys.path)
sys.argv[1:1] = "notebook --ip=192.168.45.135 --profile=zope".split()
scripts = ipython=ipzopenb
...
[versions]
Jinja2 = 2.7.2
Pygments = 1.6
Sphinx = 1.2.2