Jupyter Lab使用虚拟环境中出现的两个问题

base 环境是python3.8.3, 虚拟环境使用Python 2.7,

需要用jupyter lab切换内核方便对比记笔记之类的

 

1.创建虚拟环境,并进入虚拟环境

conda create -n py2 python=2.7

#创建时也可以将ipykernel 直接加进去

conda activate py2

2.安装ipykernel(这一步已经有些小问题了,但可以继续进行)

conda install ipykernel

# 或pip install -U ipykernel

3.

python2 -m ipykernel install --user

这一步报第一个错误

ImportError: No module named functools_lru_cache

然后直接尝试了另一种方法,增加kernel配置文件。在安装路径/share/jupyter/kernels下复制原有的文件夹,修改其中的kernel.json。

a.将路径改为虚拟环境解释器所在的路径;b.将展示名称改掉,像下面一样

{

"argv": [

"D:/miniconda/envs/py2/python.exe",

"-m",

"ipykernel_launcher",

"-f",

"{connection_file}"

],

"display_name": "Python2",

"language": "python"

}

4.启动jupyter lab 后可以看到python2 的kernel,但是此kernel 无法启动,查看日志,还是因为之前的functools_lru_cache模块找不到,这个问题绕不过去

解决方法:安装一个backports.functools_lru_cache

# pip uninstall backports.functools_lru_cache 

pip install backports.functools_lru_cache

第一个问题解决了,启动jupyterlab,出现了第二个错误AttributeError: type object 'IOLoop' has no attribute 'initialized'

原因:

tornado版本为5.x过高,不支持jupyter notebook.

解决方法:

python2 环境中 conda install tornado=4.5

总结

第一个错误:ImportError: No module named functools_lru_cache

解决办法:虚拟环境python2中

pip uninstall backports.functools_lru_cache

pip install backports.functools_lru_cache

 

第二个错误:

AttributeError: type object 'IOLoop' has no attribute 'initialized'

解决办法:

虚拟环境python2中

conda install tornado=4.5

 PS:当我想复现这两个错误时,重新创建的环境中并没有出现这两个错误>.<不是很明白为什么

你可能感兴趣的:(conda,python,anaconda)