jupyter的安装和使用

1.jupyter安装

pip安装jupyter

pip install jupyter

参考:Caffe学习系列(13):数据可视化环境(python接口)配置

2.jupyter使用

启动jupyter

jupyter notebook --ip=0.0.0.0 --port=8888

 已经将容器的端口8888映射到主机端口9528,在虚拟机上需要用localhost:9528访问,在主机上需要用
虚拟机ip:9528访问

3.centos

virtualenv venv

source venv/bin/activate

使用 pip 安装 Jupyter

我们使用 pip 命令安装 Jupyter:

pip install ipython jupyter notebook

配置 Jupyter Notebook

建立项目目录

我们先为 Jupyter 相关文件准备一个目录:

mkdir /data/jupyter

cd /data/jupyter

再建立一个目录作为 Jupyter 运行的根目录:

mkdir /data/jupyter/root

准备密码密文

由于我们将以需要密码验证的模式启动 Jupyter,所以我们要预先生成所需的密码对应的密文。

生成密文

使用下面的命令,创建一个密文的密码:

python -c "import IPython;print IPython.lib.passwd()"

执行后需要输入并确认密码,然后程序会返回一个 'sha1:...' 的密文,我们接下来将会用到它。

修改配置

生成配置文件

我们使用 --generate-config 来参数生成默认配置文件:

jupyter notebook --generate-config --allow-root

生成的配置文件在 /root/.jupyter/ 目录下,可以点此编辑配置。

修改配置

然后在配置文件最下方加入以下配置:

c.NotebookApp.ip = '*'

c.NotebookApp.allow_root = True

c.NotebookApp.open_browser = False

c.NotebookApp.port = 8888

c.NotebookApp.password = u'刚才生成的密文(sha:...)'

c.ContentsManager.root_dir = '/data/jupyter/root'

其中:

c.NotebookApp.password 请将上一步中密文填入此项,包括 sha: 部分。

你也可以直接配置或使用 Nginx 将服务代理到 80 或 443 端口。

启动 Jupyter Notebook

直接启动

使用以下指令启动 Jupyter Notebook:

jupyter notebook

此时,访问 http://服务器ip地址:8888 即可进入 Jupyter 首页。

创建 Notebook

后台运行

直接以 jupyter notebook 命令启动 Jupyter 的方式在连接断开时将会中断,所以我们需要让 Jupyter 服务在后台常驻。

先按下 Ctrl + C 并输入 y 停止 Jupyter 服务,然后执行以下命令:

nohup jupyter notebook > /data/jupyter/jupyter.log 2>&1 &

该命令将使得 Jupyter 在后台运行,并将日志写在 /data/jupyter/jupyter.log 文件中。

原文地址:https://www.cnblogs.com/zhoulixue/p/6428196.html