juypyter notebook安装

Centos 8

Centos 8 云主机

Centos 8 云主机安全组暴露端口

云主机 添加安全组将juypyter端口暴露出去(端口与juypyter指定端口一直),通过公网ip加端口号进行访问

安装前环境

python版本3.6.8

[root@ecs-kc1-large-2-linux-20200825091713 ~]# python3
Python 3.6.8 (default, Nov 21 2019, 19:02:24) 
[GCC 8.3.1 20190507 (Red Hat 8.3.1-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

安装juypyter notebook

更新pip

使用清华源下载(未修改配置文件临时生效)-i https://pypi.tuna.tsinghua.edu.cn/simple

pip3 install --upgrade -i https://pypi.tuna.tsinghua.edu.cn/simple pip



解决依赖

  在准备安装python3和pip3时,请先安装依赖环境:
# 一定要先装!不然会出现如下例一连串连锁反应的bug
yum -y install libxml2-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel gcc gcc-c++ libstdc++-devel libffi-devel python36-devel libxslt libxml2





####################################报错信息#########
# wheel 本质上是一个zip 包格式,用于 python 模块的安装,它的出现是为了替代 Eggs
pip3 install wheel

# 如果不安装会报错:
#   Using legacy 'setup.py install' for cffi, since package 'wheel' is not installed.      (由于未安装软件包“ wheel”,因此将旧版“ setup.py install”用于cffi。)

# ---

yum -y install libffi-devel
# 如果不安装会报错(基本上就死这了):
# c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory

# ---


# python3以后版本使用加上版本号,否者python-devel
yum -y install python36-devel

# 如果不安装会报错:
#       c/_cffi_backend.c:2:10: fatal error: Python.h: No such file or directory      (c / _cffi_backend.c:2:10:致命错误:Python.h:无此类文件或目录)
#            error: command 'gcc' failed with exit status 1      (错误:命令“ gcc”失败,退出状态为1)       排查:(通过在命令行键入gcc命令是存在的,是执行失败)
# 原因:系统中没有python.h的原因,是因为没有安装python的开发版,即Python-devel这个包

# ---

# 安装gcc,否则argon2_cffi无法安装
yum -y install gcc

# 安装argon2_cffi
pip3 install argon2_cffi

#      报错信息Building wheels for collected packages: argon2-cffi, pyzmq      (用于收集包装的建筑轮子:argon2-cffi,pyzmq)

#                    Building wheel for argon2-cffi (PEP 517) ... error      (argon2-cffi(PEP 517)的建筑车轮...错误)


安装notebook

(官网安装使用的就是这个包)以然使用临时生效清华源下载 快

pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple notebook

Jupyter Notebook 添加代码自动补全功能

如果之前安装过显示目录功能的话,这一步骤可以跳过

pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple  jupyter_contrib_nbextensions

配置代码自动补全功能

安装完之后需要配置 nbextension,注意配置的时候要确保已关闭 Jupyter Notebook

jupyter contrib nbextension install --user --skip-running-check

启动 Jupyter Notebook

上面两个步骤都没报错后,启动 Jupyter Notebook,上面选项栏会出现 Nbextensions 的选项,点开 Nbextensions 的选项,并勾选 Hinterland, Jupyter Lab 中的自动补全功能, 按 Tab 键即可使用

# 设置Jupyter Notebook登陆密码
jupyter notebook  password


# ---

# 启动Jupyter Notebook
jupyter notebook  --ip=0.0.0.0   --no-browser --allow-root
或
nohup jupyter notebook  --ip=0.0.0.0   --no-browser --allow-root & 

       在后台运行,查看地址cat nohup.out
# ---

# list    列出当前正在运行的笔记本服务器。
# password      设置笔记本服务器的密码。
# --port=      笔记本服务器将监听的端口(默认值:8888)
# --ip=            笔记本服务器将监听的IP地址。(0.0.0.0所有地址,或者是公共对外的地址)
# --allow-root      不建议以root身份运行。 使用--allow-root绕过。
# --no-browser      启动后不要在浏览器中打开笔记本。
# 启动 Jupyter Notebook,勾选设置

关闭nftables防火墙

systemctl stop nftables

运行Jupyter Notebook容器

  启动centos7基础镜像自己创建
# 宿主机创建关联的目录(需要提前创建)
mkdir -pv ~/jovyan/work

# 启动容器,暴露端口,关联卷,宿主机的家目录下的jovyan/work目录下,关联到容器内的家目录下
podman run --name JupyterNotebook -dit --rm -p 10000:8888 -v ~/jovyan/work:/home/jovyan/work/ docker.io/library/centos:centos7

# 进入容器进行安装
podman exec -it JupyterNotebook /bin/bash

# 安装python
yum -y install python3

# 后面安装使用上面提供的安装方法(可以切换到cd /home/jovyan/work/这个容器内的工作目录在启动 Jupyter Notebook让其工作在关联的目录下)
posted @ 2020-08-25 18:35  给文明以岁月  阅读(813)  评论(0)    收藏  举报