jupyter错误ImportError:无法导入名称路径

时间:2017-05-10 11:15:23

标签: python pip ipython jupyter-notebook jupyter

在jupyter上启动python notebook时遇到错误:

    Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/local/lib/python2.7/dist-packages/ipykernel_launcher.py", line 15, in <module>
    from ipykernel import kernelapp as app
  File "/usr/local/lib/python2.7/dist-packages/ipykernel/__init__.py", line 2, in <module>
    from .connect import *
  File "/usr/local/lib/python2.7/dist-packages/ipykernel/connect.py", line 14, in <module>
    from IPython.paths import get_ipython_dir
ImportError: No module named paths

以下是我的内核列表:

martiner@devubuntu:~$ jupyter kernelspec list
Available kernels:
  javascript    /home/martiner/.local/share/jupyter/kernels/javascript
  python2       /usr/local/share/jupyter/kernels/python2

以及其他一些信息:

martiner@devubuntu:~$ jupyter kernelspec list
Available kernels:
  javascript    /home/martiner/.local/share/jupyter/kernels/javascript
  python2       /usr/local/share/jupyter/kernels/python2
martiner@devubuntu:~$ cat /usr/local/lib/python2.7/dist-packages/*.pth
    import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('backports',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('backports', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('backports', [os.path.dirname(p)])));m = m or sys.modules.setdefault('backports', types.ModuleType('backports'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
import sys; sys.__plen = len(sys.path)
./SOMPY-1.0-py2.7.egg
./numexpr-2.6.1-py2.7-linux-x86_64.egg
/usr/lib/python2.7/dist-packages
import sys; new = sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p = getattr(sys, '__egginsert', 0); sys.path[p:p] = new; sys.__egginsert = p + len(new)

更新

这只在我运行时才有效:

ipython notebook

但如果我跑:

jupyter-notebook

然后打开一个笔记本,我得到内核错误。

1 个答案:

答案 0 :(得分:0)

这是因为apt-get软件包管理器和ipython安装的ipython的版本冲突是由pip:

所以从apt-get卸载所有版本的ipython,如下所示:

sudo apt-get remove ipython ipython-notebook ipython-notebook-common

也从pip中移除:jupyter和ipython

sudo pip uninstall jupyter 
sudo pip uninstall ipython  

由于ipython是jupyter的一部分,所以只需重新安装jupyter

sudo pip install jupyter 

这应该有帮助!!!