jupyter notebook 添加kernel时,报错:ImportError: cannot import name 'create_prompt_application'

0x00

最近在学tensorflow风格转换时,用到了jupyter,不过遇到了一些错误问题,写此文章,以备后患。

我在卸载重新安装ipython后,发现prompt-toolkit-1.0.15变成了prompt-toolkit-2.0.9。

0x01

jupyter notebook 添加kernel时发现没有ipykernel这个模块,安装它。如果想了解、掌握以下一些命令,可参考:https://blog.csdn.net/yumengzth/article/details/95629460

(image_shift) zth@yixiang:~$ python -m ipykernel install --user --name image_shift --display-name "image_shift"
/home/zth/anaconda3/envs/image_shift/bin/python: No module named ipykernel.__main__; 'ipykernel' is a package and cannot be directly executed
(image_shift) zth@yixiang:~$ jupyter kernelspec list
[ListKernelSpecs] WARNING | Native kernel (python3) is not available
[ListKernelSpecs] WARNING | Native kernel (python3) is not available
No kernels available
(image_shift) zth@yixiang:~$ conda install -n image_shift ipykernel
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 4.5.11
  latest version: 4.7.5

Please update conda by running

    $ conda update -n base -c defaults conda



## Package Plan ##

  environment location: /home/zth/anaconda3/envs/image_shift

  added / updated specs: 
    - ipykernel


The following NEW packages will be INSTALLED:

    ipykernel: 4.10.0-py35_0
    ipython:   6.5.0-py35_0 

Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: done
Executing transaction: done

0x02

再次执行添加kernel语句时,又报新错。

(image_shift) zth@yixiang:~$ python -m ipykernel install --user --name image_shift --display-name "image_shift"
Traceback (most recent call last):
  File "/home/zth/anaconda3/envs/image_shift/lib/python3.5/runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/home/zth/anaconda3/envs/image_shift/lib/python3.5/runpy.py", line 142, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/home/zth/anaconda3/envs/image_shift/lib/python3.5/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "/home/zth/anaconda3/envs/image_shift/lib/python3.5/site-packages/ipykernel/__init__.py", line 2, in <module>
    from .connect import *
  File "/home/zth/anaconda3/envs/image_shift/lib/python3.5/site-packages/ipykernel/connect.py", line 13, in <module>
    from IPython.core.profiledir import ProfileDir
  File "/home/zth/anaconda3/envs/image_shift/lib/python3.5/site-packages/IPython/__init__.py", line 55, in <module>
    from .terminal.embed import embed
  File "/home/zth/anaconda3/envs/image_shift/lib/python3.5/site-packages/IPython/terminal/embed.py", line 16, in <module>
    from IPython.terminal.interactiveshell import TerminalInteractiveShell
  File "/home/zth/anaconda3/envs/image_shift/lib/python3.5/site-packages/IPython/terminal/interactiveshell.py", line 22, in <module>
    from prompt_toolkit.shortcuts import create_prompt_application, create_eventloop, create_prompt_layout, create_output
ImportError: cannot import name 'create_prompt_application'

在网上查的原因是Jupyter-console与prompt-toolkit 2.0.9 不兼容,参考:https://github.com/jupyter/jupyter_console/issues/158

0x03

我将prompt-toolkit版本又降级到1.0.15,jupyter再次工作。Jupyter控制台需要一些爱啊。

(image_shift) zth@yixiang:~$ pip install 'prompt-toolkit==1.0.15'

虽然ipython 7.6.1要求prompt-toolkit的版本在2.0.0以上,但是这不影响。

可以看到jupyter notebook 添加kernel 成功。

0x04

运行jupyter notebook ,查看新建中已经有anaconda的虚拟环境image_shift。(下图中因为Python [conda env:image_shift]与image_shift是同一环境只是名字不一样而已,所以我在我的电脑上把image_shift删除了,嘻嘻嘻)

可以看到下图中右上角Python [conda env:image_shift]后有一个小圆圈,这表示可以使用虚拟环境,若是小黑点表示与虚拟环境没有连接好,不能使用该虚拟环境。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值