IPython notebook in zc.buildout not using eggs pat

2019-06-04 01:22发布

问题:

I've build an environment with zc.buildout including IPython script.

My problem is simple:

  • if I launch IPython in console, everything is OK and I get all my eggs in sys.path

  • but if I launch IPython notebook, I only get default system path.

Is there any way to include all my eggs while starting notebook?

Regards,

Thierry

回答1:

So, I guess somewhere in the notebook startup a process is forked, which means sys.path will get reset and buildout's tricks won't help.

I solved the problems as follows, although it's a bit dirty:

  1. Create an entry point as follows:

    setup(...
          entry_points = {
              'console_scripts': ['ipython = <yourpackage>.ipython:main']
          })
    
  2. Put the following in /ipython.py:

    from IPython.frontend.terminal.ipapp import launch_new_instance
    import os
    import sys
    
    def main():
        os.environ['PYTHONPATH']=':'.join(sys.path)
        sys.exit(launch_new_instance())
    

Now, running bin/ipython notebook will give you the sys.path you expect.