sys.path在python2 jupyter笔记本中运行时返回的内容与在终端中运行时返回的内容不同,这导致jupyter无法导入某些模块。
我知道我可以在启动笔记本后手动向路径添加项目,但这需要在每个笔记本的开头运行代码。有没有办法永久添加路径条目?
在终端
Python 2.7.15+ (default, Nov 27 2018, 23:36:35)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/home/joe/.local/lib/python2.7/site-packages',
'/usr/local/lib/python2.7/dist-packages',
'/usr/local/lib/python2.7/dist-packages/mesaPlot-0.0-py2.7.egg', '/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/python2.7/dist-packages/wx-3.0-gtk3'
在Jupyter中
'/home/joe/oldrebound/vistest/lib/python2.7',
'/home/joe/oldrebound/vistest/lib/python2.7/plat-x86_64-linux-gnu',
'/home/joe/oldrebound/vistest/lib/python2.7/lib-tk',
'/home/joe/oldrebound/vistest/lib/python2.7/lib-old',
'/home/joe/oldrebound/vistest/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/home/joe/oldrebound/vistest/local/lib/python2.7/site-packages',
'/home/joe/oldrebound/vistest/lib/python2.7/site-packages',
'/home/joe/oldrebound/vistest/local/lib/python2.7/site-packages/IPython/extensions',
'/home/joe/.ipython'