Python语法简洁清晰,具有丰富和强大的库,已经成为运维开发人员居家旅行必备的工具了;而jupyter工具又是一个非常友好的Web界面的Python IDE工具;至于详细的介绍请参考度娘吧!
其它不多说,今天讲解一下在Centos7_x64下安装jupyter工具;
默认Centos7自带的Python版本为:Python 2.7.5 ,因为Python现阶段有两大版本;Python2和Python3 所以今天我们也要安装上一个Python3的版,实现两个版本共存;
系统:最小化安装[习惯性]
关闭防火墙:systemctl stop firewalld && systemctl disable firewalld
禁用SELINUX:
sed -i ‘s#SELINUX=enforcing#SELINUX=disabled#g’ /etc/selinux/config |
#添加EPLE源:
rpm -ivh http://mirrors.yun-idc.com/epel/epel-release-latest-7.noarch.rpm |
#安装部分可能用到的依赖包:
yum install vim openssl-devel readline-devel python-devel python-pip -y
Python-3.5.2 编译安装:
tar xf Python-3.5.2.tgz
cd Python-3.5.2
./configure --prefix=/usr/local/python-3.5.2
make && make install
#创建一个软连接:
ln -sf /usr/local/python-3.5.2/bin/python3 /usr/bin/python3
ln -sf /usr/local/python-3.5.2/bin/pip3 /usr/bin/pip3
这样就安装完Python3了;
#接下来安装jupyter:
pip install jupyter //这命令默认使用的是Python2.7.5版本安装;
安装完后即可以启动:jupyter-notebook
jupyter-notebook
由于我是在虚拟机上的一个系统,如果直接启动是无法 打开jupyter-notebook 页面的,这里修改一下配置文件:
#默认情况下配置文件保存在:/root/.jupyter/jupyter_notebook_config.py 如果此文件不存在,可以刷新出来:
[root@pydev ~]# jupyter notebook --generate-config
创建一个密码:[这样就不用每次复制URL地址]
[root@pydev ~]# python Python 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from notebook.auth import passwd >>> passwd() Enter password: Verify password: 'sha1:c1ebae9ce1b5:0c25328cd843b9f57b2043de1bb55f464d023939' >>>
修改配置文件中的IP地址工作目录,并添加一个认证密码:
#158 c.NotebookApp.ip = 'localhost' 改成: 158 c.NotebookApp.ip = '0.0.0.0' 这样就可以外部访问了,默认只有在本机可以访问的; #修改配置文件中的工作目录;[固定一个工作目录] #195 c.NotebookApp.notebook_dir = u'' 改成: 195 c.NotebookApp.notebook_dir = u'/opt/pydev' 210 #c.NotebookApp.password = u'' 改成上面生成的密码:[123456] c.NotebookApp.password = u'sha1:c1ebae9ce1b5:0c25328cd843b9f57b2043de1bb55f464d023939'
#保存,重新运行程序:
jupyter-notebook
URL地址:10.0.10.253:8888
密码:123456
经过上面操作已经完成默认Python2的配置了,但是jupyter-notebook界面上只有一个Python2的版本;不信可以查看一下:
[root@pydev pydev]# jupyter-kernelspec list Available kernels: python2 /usr/lib/python2.7/site-packages/ipykernel/resources
所以接下来要配置Python3的版本;
安装jupyter[注意此时使用的是pip3,就是上面安装的Python3.5.2版本]
pip3 install ipykernel python3 -m ipykernel install --name python3 --display-name "Python3.5.2"
#再次查看内核空间:[已经多了一个Python的模块了]
[root@pydev ~]# jupyter-kernelspec list
重新启动:jupyter-notebook
登陆到http://10.0.10.253:8888/ 输入密码,点击右边的New即可以看到如下图:
怎么验证是否成功呢?
#Python2是直接可以打印出结果的:
#Python3如果不带括号是会报错的:
查看Python版本的命令:
!python -V
其它仔细看下图kernel.json文件,就是多了一个Python3的执行程序配置:
至此,jupyter-notebook 多个Python版本切换就完成了;