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

重要参考:

相关推荐
技术咖啡馆C1 小时前
二、IDE集成DeepSeek保姆级教学(使用篇)
ide·ai编程·idea-plugin·deepseek
新时代丘鸣山12 小时前
Idea java项目结构介绍
java·ide·intellij-idea
亚林瓜子16 小时前
IDEA撤销commit
java·ide·intellij-idea
code_talking18 小时前
Python学习第十七天之PyTorch保姆级安装
人工智能·pytorch·python·conda
马圈圈马18 小时前
服务器间迁移conda环境
运维·服务器·pytorch·深度学习·conda
coco_1998_218 小时前
【Win10】Anaconda + Pycharm 环境搭建教程
ide·python·pycharm
你若盛开,清风自来!1 天前
在VSCode中安装jupyter跑.ipynb格式文件
vscode·jupyter·pyathon
影魅周影1 天前
(IDE接入DeepSeek)简单了解DeepSeek接入辅助开发与本地部署建议
ide
运维开发王义杰1 天前
理解 AI IDE 中的代码库索引:深入探讨 Cursor 的实现
ide·人工智能
张3蜂1 天前
现在集成大模型的IDE,哪种开发效率最高
ide