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

重要参考:

相关推荐
Diligently_9 天前
idea 中vm option 配置
java·ide·intellij-idea
我命由我123459 天前
在 Android Studio 中,新建 AIDL 文件按钮是灰色
android·ide·android studio·安卓·android jetpack·android-studio·android runtime
AC赳赳老秦9 天前
云原生AI故障排查新趋势:利用DeepSeek实现高效定位部署报错与性能瓶颈
ide·人工智能·python·云原生·prometheus·ai-native·deepseek
Nightmare0049 天前
切换conda环境的时候输出zstandard could not be imported. Running without .conda support.
开发语言·python·conda
被制作时长两年半的个人练习生9 天前
claude code for vscode 配置 qwen3.5
ide·vscode·claude code·qwen3.5
开发者小天9 天前
python中使用jupyter notebook 绘制正态分布直方图 密度图 小提琴图 模仿企鹅喙长分布图
开发语言·python·jupyter
圣心9 天前
Visual Studio Code 中的 AI 智能操作
ide·人工智能·vscode
吹牛不交税9 天前
关于vscode左侧资源管理器目录层级疑似异常的问题
ide·vscode·编辑器
xixi09249 天前
selenium IDE安装使用教程
ide·selenium·测试工具
墨染天姬9 天前
【AI】conda常用指令
人工智能·conda