通过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开启防火墙相关命令请自行百度。

重要参考:

相关推荐
梦幻通灵7 小时前
IDEA通过Contince接入Deepseek
java·ide·intellij-idea
莲动渔舟12 小时前
赶AI大潮:在VSCode中使用DeepSeek及近百种模型的极简方法
ide·人工智能·vscode·deepseek
咩咩大主教13 小时前
VSCode运行Go程序报错:Unable to process `evaluate`: debuggee is running
开发语言·ide·vscode·golang·编辑器
佛曰我不想说话13 小时前
通过VSCode直接连接使用 GPT的编程助手
ide·vscode·copilot
~|Bernard|14 小时前
conda和conda-forge区别?怎么选用?
人工智能·深度学习·conda·transformer
温酒往事·17 小时前
无缝对接[系列2]:在VSCode中继续接入本地DeepSeek的完整指南
ide·vscode·编辑器
半旧夜夏19 小时前
阿里云IOT消息处理
java·ide·git·物联网·spring·阿里云
剑客狼心20 小时前
Android Studio:RxBus 和 Observable事件流对比
android·ide·android studio
溯源0061 天前
在conda虚拟环境中安装jupyter lab-----deepseek问答记录
ide·jupyter·conda
大G哥1 天前
在IntelliJIDEA中使用Gradle创建Web项目的步骤
java·前端·ide·intellij-idea