jupyter使用anaconda虚拟环境

时间:2025-05-08 07:11:22

一、创建一个虚拟环境

conda create -n new python=3.7
# 其中“new”为新创建虚拟环境名称,python版本根据需要设置

二、进入虚拟环境,并安装jupyter

# 进入虚拟环境
activate new
# 安装jupyter 和 notebook
pip install jupyter notebook

三、安装ipykernel,并进行相关操作

pip install --user ipykernel
# 其中“--user”可以不键入,对本虚拟环境无影响
# 将虚拟环境添加到jupyter中,其中“new”为虚拟环境在jupyter中显示的名称,与虚拟环境名称可不一致,可自行设置
python -m ipykernel install --user --name= new

# 查看jupyter是否已添加虚拟环境
jupyter kernelspec list

# 删除相应的虚拟环境
jupyter kernelspec uninstall new

四、jupyter连接不上kernel(内核)

 jupyter连接不上内核是因为软件包版本不适配,所以只要调整相关软件包的版本即可。

一般,pyzmq软件包不适配是最常见的问题,解决方法如下:

# 卸载pyzmq库
pip uninstall pyzmq

# 下载19.0.2这个版本的pyzmq库
pip install pyzmq==19.0.2