小工具知识网

当前位置: 首页 > 行业知识 > 环境配置 |Jupyter lab/Jupyter Notebook 安装与设置

行业知识

环境配置 |Jupyter lab/Jupyter Notebook 安装与设置

2026-10-22 07:55:26 来源:互联网转载

ipynb使用Jupyterlab/Jupyter Notebook 来编写Python程序时的文件,在使用时,可以现转换为标准的.py的python文件

1.Jupyter Lab

1.1.下载安装

环境:Linux

pip install jupyterlab

1.2.使用

jupyter lab

 点击后进入

 1.3.jupyter lab更换内核

因为我的是在anaconda的虚拟环境进行设置,所以先进入虚拟环境

 

conda activate envpip install ipykernel

将conda环境写入jupyter的kernel中

--name 环境名称

--display-name 在jupyter lab看到的别名

python -m ipykernel install --user  --name sam --display-name "sam"

 

再进入jupyter

jupyter lab# jupyter lab --ip=0.0.0.0 --allow-root

在Jupyterlab界面上方的kernel---->change kernel中选择即可。或者新建文件的时候直接选择不同版本的环境

2.Jupyter Notebook

2.1.下载安装

pip install jupyter notebook#pip install -i https://pypi.tuna.tsinghua.edu.cn/simple jupyter

在conda的虚拟环境中安装

conda install -y jupyter

其他

pip install pyzmq

2.2.使用

jupyter notebook

进入到ipynb文件对应的目录

2.3.jupyter notebook更换内核(与1.3相同)

3.将ipynb文件转化成python文件

jupyter nbconvert --to script *.ipynb

Q&A

Q1:Jupyter Notebook和jupyter lab的区别?

Jupyter Notebook 是一个款以网页为基础的交互计算环境,可以创建Jupyter的文档,支持多种语言,包括Python, Julia, R等等。广泛用于数据分析,数据可视化和其他的交互和探索性计算中。

JupyterLab 是包括了Notebook的下一代用户界面。有模块化的界面,可以在同一个窗口同时打开好几个notebook或文件(HTML, TXT, Markdown等等),都以标签的形式展示,于是就更像是一个IDE。

PS

【PS1】安装第三库时出现错误

输入pip install google-colab出现错误

原因分析:觉得是setuptools的版本问题,所以尝试conda安装

conda install -c conda-forge google-colab

安装后问题解决

【PS2】AttributeError: module 'IPython.utils.traitlets' has no attribute 'Unicode'

打开源文件

 ~/anaconda3/envs/sam/lib/python3.8/site-packages/google/colab/data_table.py

将 库里的原本的代码from IPython.utils import traitlets as _traitlets删除或注释掉

改为 import traitlets as _traitlets

 

然后就解决啦~

相关错误ModuleNotFoundError: No module named 'traitlets.config.application'

 将原本的traitlets-5.9.0卸载,再安装就好啦

pip uninstall traitlets==5.9.0pip install traitlets==5.14.1

【PS3】RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! (when checking argument for argument mat2 in method wrapper_CUDA_mm)

未解决

上一篇:揭秘.NET源码阅读秘籍,轻松掌握源码阅读技巧!

下一篇:wr自然拼读怎么读?