1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > python安装jupyterlab_jupyter及jupyterlab安装使用

python安装jupyterlab_jupyter及jupyterlab安装使用

时间:2022-03-19 03:02:06

相关推荐

python安装jupyterlab_jupyter及jupyterlab安装使用

一.jupyter安装及简单使用

Jupyther notebook(曾经的Ipython notebook),是一个可以把代码、图像、注释、公式和作图集于一处,实现可读性及可视化分析的工具,支持多种编程语言。官方使用手册。安装前,你需要装好python环境,并且安装pip包管理器并更新

pip install --upgrade pip

pip3 install --upgrade pip

1.安装jupyter

Python2

pip install jupyter notebook

(python -m pip install jupyter)

Python3

pip3 install jupyter notebook

(python3 -m pip install jupyter)

2.配置jupyter(可选)

生成jupyter配置文件:

jupyter notebook --generate-config

此时会在你的个人用户目录下的.jupyter 下生成配置文件 jupyter_notebook_config.py,打开以后找到如下一行:

#c.NotebookApp.ip = 'localhost'

这里配置的是是允许访问的IP地址,这里改为*,意思为允许所有ip连接。:

c.NotebookApp.ip = '*'

注:如果你在服务器上运行,需要采用这种方式,并且为了安全考虑,最好将c.NotebookApp.ip的值设置为Client的ip。

3.运行jupyter

运行jupyter的命令为:

jupyter notebook

(ipython notebook)

如果你只是本地运行,并且没有生成配置文件,那么运行命令如下:

jupyter notebook --ip=0.0.0.0

jupyter notebook --ip=0.0.0.0 --allow-root (root权限运行)

4.jupyter必要环境配置

(1) 生成环境配置文件ipython profile create

此时会在你的家目录生成配置文件.ipython/profile_default/ipython_kernel_config.py

(2) 运行代码后自动显示变量值

直接在该文件的头部添加代码

c = get_config()

c.InteractiveShell.ast_node_interactivity = "all"

(3) 中文编码问题

vi ~/.ipython/ipythonrc

readline_parse_and_bind "\M-i": " "

readline_parse_and_bind "\M-o": "\d\d\d\d"

readline_parse_and_bind "\M-I": "\d\d\d\d

注释掉这3行

(4) matplotlib作图显示中文

需要设置中文字体,否则中文会乱码。

import matplotlib.pyplot as plt

plt.rc('font', family='Microsoft YaHei Mono', size=12)

5.常用快捷键在当前cell的上一层添加cell:A

在当前cell的下一蹭添加cell:B

双击d:删除当前cell

撤销对某个cell的删除:z

当前的cell进入编辑模式:Enter

退出当前cell的编辑模式:Esc

执行当前cell并跳到下一个cell:Shift Enter

执行当前cell执行后不调到下一个cell:Ctrl Enter

向下选择多个cell:Shift + J 或 Shift + Down

向上选择多个cell:Shift + K 或 Shift + Up

合并cell:Shift + M

在代码中查找、替换,忽略输出:Esc + F

在cell和输出结果间切换:Esc + O

快速跳转到首个cell:Crtl Home

快速跳转到最后一个cell:Crtl End

m:进入markdown模式,编写md的文档进行描述说明

为当前的cell加入line number:单L

将当前的cell转化为具有一级标题的maskdown:单1

将当前的cell转化为具有二级标题的maskdown:单2

将当前的cell转化为具有三级标题的maskdown:单3

为一行或者多行添加/取消注释:Crtl /

在浏览器的各个Tab之间切换:Crtl PgUp和Crtl PgDn

二.JupyterLab安装使用

JupyterLab是Jupyter Notebook的增强版本,看起来更像是一个IDE。

1.安装jupyterlab

Python2

pip install jupyterlab

(python -m pip install jupyterlab)

Python3

pip3 install jupyterlab

(python3 -m pip install jupyterlab)

如果你使用的Jupyter版本早于5.3,那么你还需要运行以下命令来启动JupyterLab服务组件。

jupyter serverextension enable --p

jupyterlab --sys-prefix

2.运行jupyterlab

使用以下命令运行JupyterLab:

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

3.管理jupyterlab

查看令牌$ jupyter notebook list

http://localhost:8888/?token=c8de56fa... :: /Users/you/notebooks

列出已安装扩展jupyter labextension list

卸载已安装扩展jupyter labextension uninstall my-extension

其中my-extension是扩展名列表中的打印名称。您也可以使用此命令卸载核心扩展(以后可以随时重新安装核心扩展)。

参考

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。