众所周知,CentOS7 默认安装python2.7 ,但是现在大多数用的是python3,所以我们先安装python3, 再安装jupyter notebook

一、安装python3

注意:安装python3时不要卸载自带的python2.7,直接安装即可。

1. 安装各种环境

yum -y groupinstall "Development tools"
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

2. 下载python安装包

wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz

3.创建一个空的文件夹用来当做安装目录

mkdir /usr/local/python3

4. 解压、安装

tar -xvJf  Python-3.6.2.tar.xz
cd Python-3.6.2
./configure --prefix=/usr/local/python3
make && make install

5. 建立软连接

ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

恭喜你,python3安装完成,接下来进入第二步,安装Jupyter Notebook

 

二、 安装Jupyter Notebook

1. 安装jupyter notebook

pip3 install  jupyter

2. 生成配置文件(因为jupyter notebook没有配置文件,所以需要我们来手动生成)

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

这里需要注意,如果你的账户为root,则必须要添加 --allow-root 这一项,如果不是root用户,加不加均可

3. 试着启动一下Jupyter Notebook

命令行输入jupyter notebook,如果可以启动成功的话,应显示如下:

jupyter notebook新建没有python怎么办_Python

如果出现拨错的话也不要慌张,仔细看一下报错信息,一般都是很简单的错误

如果能够启动成功的话,那么恭喜你,已经完成了80%了

4. 生成连接密码

python3

In [1]: from notebook.auth import passwd

In [2]: passwd()

Enter password:

Verify password:

Out[2]: 'sha1:xxxxxx.....'

In [3]: quit()

在输入密码之后会生成一系列字符串,记得把 sha1:xxxxxx..... 记下来,之后退出python3

5. 修改配置文件

进入配置文件

vi  ~/.jupyter/jupyter_notebook_config.py

按 i 进入插入模式,将下面的代码复制到文件中,将刚刚记住的密文替换掉第二行的 sha1:xxxxxx.....

c.NotebookApp.ip='*'

c.NotebookApp.password = u'sha1:xxxxxx.....'

c.NotebookApp.open_browser = False

c.NotebookApp.port =8800

按下Esc ,输入 :wq ,点击回车退出文件

至此,Jupyter Notebook配置完成

我们上面使用了8800端口,我们知道阿里云云服务器是有防火墙的,我们需要设置防火墙让8800端口可以正常工作

6. 修改安全组策略

打开阿里云服务器管理界面,找到云服务器的安全组策略

jupyter notebook新建没有python怎么办_配置文件_02

在入方向添加安全组规则,我们使用的是8800端口,所以我们设置开放8800端口,点击添加安全组规则,按照提示填好

jupyter notebook新建没有python怎么办_python_03

切换到出方向,再次添加安全组规则

jupyter notebook新建没有python怎么办_centos_04

至此 Jupyter Notebook 就部署完成啦,在本地电脑的浏览器中输入 IP:8800 就可以访问啦,访问之间要输入自己设置的密码

jupyter notebook新建没有python怎么办_Python_05