通过Conda安装jupyter notebook

目录

  • [1、通过Conda安装jupyter notebook](#1、通过Conda安装jupyter notebook)
    • [1.1 windows操作系统上安装jupyter notebook](#1.1 windows操作系统上安装jupyter notebook)
    • [1.2 centos/ubuntu操作系统上安装](#1.2 centos/ubuntu操作系统上安装)

1、通过Conda安装jupyter notebook

首先,安装好Anaconda(安装步骤略,Ubuntu的操作系统可以参考下面的文章)

超详细Ubuntu安装Anaconda步骤+Anconda常用命令

1.1 windows操作系统上安装jupyter notebook

Step 1创建一个conda环境

通过命令conda create -n <envname> <python版本> 创建某个环境,比如叫做deeplearning

bash 复制代码
$(base) > conda create -n deeplearning python=3.9

Step2激活(使用)该环境 conda activate <envname>

bash 复制代码
$(base) > conda activate deeplearning
$(deeplearning)> 

Step3执行安装命令

bash 复制代码
$(deeplearning)> conda install jupyter # 或者 pip install jupyter
bash 复制代码
$(deeplearning)> conda install ipykernel # 或者 pip install ipykernel
bash 复制代码
$(deeplearning)> python -m ipykernel install --user --name 本地环境名称 --display-name
比如:
$(deeplearning)>  python -m ipykernel install --user --name deeplearning --display-name deeplearning

Step4、启动jupyter notebook

bash 复制代码
$(deeplearning)> jupyter notebook

1.2 centos/ubuntu操作系统上安装

Step 1创建一个conda环境

bash 复制代码
$(base) > conda create -n deeplearning python=3.9

Step2、 激活(使用)该环境 conda activate <envname>

bash 复制代码
$(base) > conda activate deeplearning
$(deeplearning)> 

Step3执行安装命令 并 启动 jupyter notebook

bash 复制代码
$(deeplearning)> conda install jupyter

如果接下来能通过jupyter notebook启动,那么就不用安装ipykernel了。(可能环境会自带)

如果使用``jupyter notebook命令启动报错,那么就安装下ipykernel(conda install ipykernel`)

貌似centos、ubuntu操作系统不用使用 python -m ipykernel install --user --name 本地环境名称 --display-name


接下来的步骤是,远程访问服务器(centos/ubuntu)的jupyter notebook,如果是本地的话,那么应该直接可以打开浏览器用了。但我需要远程访问它,但遇到的情况是,输入http://服务器ip:8888后,界面没反应,所以要做如下设置。

Step4设置密码获得秘钥

bash 复制代码
$ (deeplearning)> ipython

from jupyter_server.auth import passwd;
passwd(algorithm='sha1') 
Enter password:
Verify password:
#Out[2]:'sha1:f56b3b8......'

记住这个passwd:sha1:f56b3b8......,等下要写在配置文件中。

Step5生成配置文件

bash 复制代码
$ (deeplearning)> jupyter notebook --generate-config

注:如果不使用这条命令,那么找不到/root/.jupyter/jupyter_notebook_config.py这个配置文件!

Step6编辑配置文件

bash 复制代码
$ (deeplearning)> vim /root/.jupyter/jupyter_notebook_config.py

可以看到这个文件全部注释掉的,可以挨个挨个找来设置,也可以把下面这段代码复制进去,然后稍作修改:

bash 复制代码
c.ServerApp.ip = '0.0.0.0' #表示所有ip都可以访问,设置成'*'也可以
c.ServerApp.password = 'sha1:f56b3b8......' # 刚才记下来的
c.ServerApp.open_browser = False
c.ServerApp.port = 8888 #设置的
c.ServerApp.allow_remote_access = True
c.ServerApp.notebook_dir = '/home/wxh/MyJupyterSpace' #设置notebook启动的根目录
c.ServerApp.allow_root = True #如果每次使用启动时要加--allow_root的话,那么可以这样设置以免每次都加

保存并退出

Step7启动jupyter notebook

bash 复制代码
$ (deeplearning)> jupyter notebook

后台启动:

bash 复制代码
$ (deeplearning)> nohup jupyter notebook >out.file 2>&1 &

注: 如果服务器启动了,远程还是访问不了http://服务器ip:8888,那么可能是操作系统防火墙的原因。

Ubuntu开启防火墙(参考:《Ubuntu常用防火墙命令》

bash 复制代码
sudo ufw status: 查看防火墙状态,inactive是关闭状态,active是开启状态
bash 复制代码
sudo ufw allow 8888:允许外部访问8888端口,协议包含tcp和udp

Centos开启防火墙相关命令请自行百度。

重要参考:

相关推荐
墨抒颖 msy.plus1 小时前
[特殊字符] 从零到一:打造你的VSCode圈复杂度分析插件
ide·vscode·编辑器·插件·cursor
北冥有鱼被烹9 小时前
【微知】vscode如何开启markdown的review模式?
ide·vscode·编辑器
携欢16 小时前
CodeQL(Mac)安装与测试(Visual Studio)简明指南
ide·vscode·macos
2301_7671139818 小时前
Conda 常用命令大全
conda
susu10830189111 天前
如何选择文件夹然后用vscode直接打开
ide·vscode·编辑器
非得登录才能看吗?1 天前
开发环境 之 编辑器、编译器、IDE梳理
ide·编辑器
艾莉丝努力练剑1 天前
GCC编译器深度解剖:从源码到可执行文件的全面探索
c++·ide·经验分享·gcc
熊猫钓鱼>_>1 天前
在VSCode中更新或安装最新版的npx和uv工具
ide·vscode·uv
吐个泡泡v1 天前
Python包管理工具全对比:pip、conda、Poetry、uv、Flit深度解析
conda·pip·uv·python包管理工具·poetry
猫头虎1 天前
IDE mac M芯片安装报错:如何解决“InsCode.app 已损坏”,无法打开
ide·vscode·macos·inscode·编辑器·idea·mac