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

重要参考:

相关推荐
猿小猴子31 分钟前
主流 AI IDE 之一的 Cursor 介绍
ide·人工智能·cursor
弱冠少年3 小时前
conda入门
conda
John Song3 小时前
conda指定包安装的channel
conda
Gene_20223 小时前
conda环境配置(一) —— 常用虚拟环境操作命令
conda
我命由我123456 小时前
VSCode - VSCode 放大与缩小代码
前端·ide·windows·vscode·前端框架·编辑器·软件工具
old_power8 小时前
VSCode 工作区配置文件通用模板创建脚本
ide·vscode·编辑器
Calvex9 小时前
PyCharm集成Conda环境
python·pycharm·conda
vortex510 小时前
在 Kali 上打造渗透测试专用的 VSCode 环境
ide·vscode·编辑器
BreezeDove11 小时前
IDEA安装&迁移IDEA配置数据位置
java·ide·intellij-idea
24K纯学渣11 小时前
Python编码格式化之PEP8编码规范
开发语言·ide·python·pycharm