【问题标题】:jupyter error ImportError: cannot import name pathjupyter错误ImportError:无法导入名称路径
【发布时间】:2017-10-09 00:11:26
【问题描述】:

在 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

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

【问题讨论】:

  • 该错误通常意味着它在某处找到旧版本的 IPython。尝试卸载所有你能找到的 IPython 副本,然后重新安装最新的。
  • 能否请您明确说明如何操作?谢谢

标签: python pip ipython jupyter-notebook jupyter


【解决方案1】:

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

所以从 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 

这应该有帮助!!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-25
    • 1970-01-01
    • 1970-01-01
    • 2019-08-06
    • 2019-11-19
    • 2016-10-27
    • 1970-01-01
    • 2019-03-23
    相关资源
    最近更新 更多