python中jupyter notebook安装教程

一、什么是Jupyter Notebook?

Jupyter Notebook是基于网页的用于交互计算的应用程序。其可被应用于全过程计算:开发、文档编写、运行代码和展示结果。

——Jupyter Notebook官方介绍

https://jupyter-notebook.readthedocs.io/en/stable/notebook.html

二、安装Jupyter Notebook


使用命令安装
conda install ipykernel
或者
pip install jupyter notebook

三、运行Jupyter Notebook

3.1 帮助


jupyter notebook --help
# 同上
jupyter notebook -h

3.2 启动


# 默认启动端口8888
jupyter notebook

# 指定端口启动
jupyter notebook --port 8889

# 指定工作目录启动
jupyter notebook --notebook-dir .

比如我在E盘下创建一个目录study,进入base环境,启动jupyter,端口是8889,指定目录命令行接入的目录


cd E:\study
conda activate base
jupyter notebook --port 8889 --notebook-dir .

在命令行终端显示内容


[I 12:21:04.177 NotebookApp] [jupyter_nbextensions_configurator] enabled 0.6.3
[W 12:21:04.903 NotebookApp] Loading JupyterLab as a classic notebook (v6) extension.
[W 2023-11-20 12:21:04.911 LabApp] 'port' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[W 2023-11-20 12:21:04.911 LabApp] 'notebook_dir' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[W 2023-11-20 12:21:04.911 LabApp] 'notebook_dir' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[I 2023-11-20 12:21:04.919 LabApp] JupyterLab extension loaded from D:\tool\anaconda\Lib\site-packages\jupyterlab
[I 2023-11-20 12:21:04.919 LabApp] JupyterLab application directory is D:\tool\anaconda\share\jupyter\lab
[I 12:21:12.314 NotebookApp] Serving notebooks from local directory: E:\study
[I 12:21:14.111 NotebookApp] Jupyter Notebook 6.5.4 is running at:
[I 12:21:14.126 NotebookApp] http://localhost:8889/?token=7c619de75e5ed07516912c78784f01af3637f4cd023ba5d4
[I 12:21:14.126 NotebookApp]  or http://127.0.0.1:8889/?token=7c619de75e5ed07516912c78784f01af3637f4cd023ba5d4
[I 12:21:14.126 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 12:21:14.236 NotebookApp]

注意:之后在Jupyter Notebook的所有操作,都请保持终端不要关闭,因为一旦关闭终端,就会断开与本地服务器的链接,你将无法在Jupyter Notebook中进行其他操作啦。

在这里插入图片描述
如果你同时启动了多个Jupyter Notebook,有的端口被占用,可以通过指定不同的端口进行启动。

四、配置Jupyter Notebook

常规的情况下,Windows和Linux/macOS的配置文件所在路径和配置文件名如下所述:

  • Windows系统的配置文件路径:C:\Users<user_name>.jupyter\

    Linux/macOS系统的配置文件路径:/Users/<user_name>/.jupyter/ 或 ~/.jupyter/

配置文件名:jupyter_notebook_config.*可以是.json文件或者.py文件

如果不存在配置文件,可通过下面命令生成

jupyter notebook --generate-config

找到该jupyter_notebook_config.py文件,并打开

在这里插入图片描述


# 指定默认工作目录
c.NotebookApp.notebook_dir = r'D:\python学习'
#允许所有IP都可访问
c.NotebookApp.ip = '*'
#将开启jupyter后在服务器上打开浏览器的选项设置为False
c.NotebookApp.open_browser = False
#指定访问端口
c.NotebookApp.port = 8888
#允许远程访问
c.NotebookApp.allow_remote_access = True   

五、Jupyter Notebook更改环境

jupyter notebook访问的时候,默认使用了anaconda的base环境。

如果需要更换环境,执行下面命令:


python -m ipykernel install --user --name 要添加的环境 --display-name "jupyter中显示的kernel名字"
python -m ipykernel install --user --name Pytorch --display-name "Pytorch"

在这里插入图片描述
查看Kernel

jupyter kernelspec list

在这里插入图片描述
删除指定Kernel

jupyter kernelspec remove pyhorch

六、Jupyter Notebook 主题更换

经测试,大部分自定义主题界面不支持自适应,因此如果需要在平板上使用jupyter,建议使用默认主题。

# 通过下面命令安装主题
pip install jupyterthemes

查看所有主题

jt -l

在这里插入图片描述

# 更换为onedork主题
jt -t onedork

在这里插入图片描述

# 下面命令回复默认主题
jt -r

在这里插入图片描述

  • 9
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
在安装Jupyter Notebook之前,您需要确认已经安装了Python编译器。您可以在Python官网上下载并安装Python编译器。然后,您可以在Cmd或者Pycharm终端运行以下命令来安装Jupyter Notebook: - 使用命令 conda install jupyter 或者 pip install jupyter 此外,如果您在Jupyter Notebook遇到了无法切换虚拟环境的问题,您可以通过安装ipykernel来解决。以下是一些相关的命令: - 安装ipykernel:python -m pip install ipykernel - 添加内核:python -m ipykernel install --user --name=kernelname --display-name showname 其,kernelname为您创建的文件夹名,showname为在Jupyter Notebook展示的内核名。 - 查看内核列表:jupyter kernelspec list - 删除内核:jupyter kernelspec remove name 这些步骤可以帮助您在Python安装Jupyter Notebook并解决相关的环境切换问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Jupyter notebook 详细安装步骤](https://blog.csdn.net/Withadream/article/details/125440035)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [pythonjupyter notebook安装教程、常用插件和拓展配置及基本使用(全面)](https://blog.csdn.net/QH2107/article/details/126238357)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

老朱2000

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值