python - IPython 笔记本内核在 zc.buildout 设置中终止

标签 python virtualenv ipython jupyter-notebook buildout

我使用 zc.buildout 来构建我的 python 应用程序环境。我想运行 IPython 笔记本并使用我的自定义包来进一步测试和开发。

[buildout]
extends = buildout.cfg

parts += 
    ipython_part

[versions]
ipython = 0.13.2
pyzmq = 13.0.2


[ipython_part]
#http://ipython.org/ipython-doc/stable/install/install.html#dependencies-for-the-ipython-html-notebook
#https://github.com/bearstech/ipython_notebook/blob/master/buildout.cfg
recipe = zc.recipe.egg
dependent-scripts = true
eggs = 
       ipython[zmq,notebook,test]
       ${myapplication:eggs}

启动笔记本可以工作,但是当我创建一个新笔记本时,内核就会死掉。

[NotebookApp] Kernel started: c7c64caf-c966-4863-b37d-11cf11901882
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named IPython.zmq.ipkernel

在 virtualenv 中运行 IPython 就像一个魅力。我的问题与build设置有关。我知道这一点answer 。有用。

关于构建和 IPython 笔记本的广泛使用,这一定是一种常见情况。是否有任何构建方法可以使其开箱即用?

最佳答案

根据this answer在笔记本启动时,进程被 fork 并丢失由 buildout 准备的 sys.path。相同的解决方案也应该适用于您的案例。

编辑:我决定在我的“开发”配方中添加一个初始化关键字:

[development]
recipe = zc.recipe.egg
eggs = ipython[all]
# ugly work-around needed for ipython nootbook
initialization =
    import sys, os
    os.environ['PYTHONPATH'] = ':'.join(sys.path)

更加干净,而且大部分都有效。

关于python - IPython 笔记本内核在 zc.buildout 设置中终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21088748/

相关文章:

python - read_csv 函数中的 low_memory 参数

python - 用于网格旋转的 Numpy einsum()

Python 3.5 - 在 Windows 下创建带子文件夹的文件夹

virtualenv - Pyenv activate 不运行带 fish shell 的激活脚本

python - virtualenv 没有设置虚拟环境

python - 如何在Python中计算一组值的密度分布?

python - 数组运算等价Python和Matlab

python - 使用OpenCV增强灯的转角检测

python - virtualenvwrapper - 环境变量不保存

python - 规范化 ID 列