Use Jupyter notebook on Fedora 28

生产环境使用 Fedora 28, 并且需要搭建一个 Jupyter 的notebook 方便使用,所搭建的Jupyter 支持单人远程 密码访问

1. 安装

安装 Jupyter , 出错

[root@dhcp-65-15 ~]# pip install jupyter
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip install --user` instead.
.
.
.
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-2.7
    copying scandir.py -> build/lib.linux-x86_64-2.7
    running build_ext
    building '_scandir' extension
    creating build/temp.linux-x86_64-2.7
    gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.7 -c _scandir.c -o build/temp.linux-x86_64-2.7/_scandir.o
    gcc: error: /usr/lib/rpm/redhat/redhat-hardened-cc1: No such file or directory
    error: command 'gcc' failed with exit status 1
    
    ----------------------------------------
Command "/usr/bin/python2 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-8KqVrv/scandir/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-IrivkV-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-8KqVrv/scandir/
You are using pip version 9.0.3, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

安装 redhat-rpm-config

[root@dhcp-65-15 ~]# yum install redhat-rpm-config

安装 python-devel

[root@dhcp-65-15 ~]# yum install python-devel

安装 notebook

[root@dhcp-65-15 ~]# pip install notebook

2. 运行

生成token 运行:

[root@dhcp-65-15 ~]# jupyter notebook --allow-root
[I 03:45:13.108 NotebookApp] Serving notebooks from local directory: /root
[I 03:45:13.108 NotebookApp] 0 active kernels
[I 03:45:13.108 NotebookApp] The Jupyter Notebook is running at:
[I 03:45:13.108 NotebookApp] http://localhost:8888/?token=60bbeb5c2ef4a8c0e15cfcb85588e265a185b46949e051e7

生成配置文件:

[root@dhcp-65-15 ~]# jupyter notebook --generate-config
Writing default config to: /root/.jupyter/jupyter_notebook_config.py

3. 配置

(1)在配置文件中配置密码:

c.NotebookApp.password = u'sha1:12a39cedb875:c97d0285f90cec397fffe96f11e5ef5e56e90fa2'

其中:加密使用 

from notebook.auth import passwd  中 password 方法进行加密
可以在 python shell 中生成

或者直接使用:
[root@dhcp-65-15 ~]# jupyter notebook password

设置密码,并直接写到配置文件中

如果没有设置密码 可以使用 jupyter notebook list 命令来查看 token 从而进行访问。

(2)允许所有ip地址访问

保持更新,转载请注明出处。

 

猜你喜欢

转载自www.cnblogs.com/xuyaowen/p/fedora-jupyter.html