Jupyter Notebook支持多python版本

Jupyter notebook里的代码有py2.7也有py3.0的,本文讲解如何使Jupyter同时支持多个python版本(python2.7.5 + python3.6.2)。

#cenos7默认安装了python2.7.5
[work@mars ~]$ python -V
Python 2.7.5

#安装python3依赖
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make -y

#安装python3
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
tar -xvJf  Python-3.6.2.tar.xz
cd Python-3.6.2
./configure prefix=/usr/local/python3    #指定安装位置
su root
make && make install
#添加软链
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
#检查版本
[root@mars ~]# python3 -V
Python 3.6.2
[root@mars ~]# pip3 install --upgrade pip
#安装常用python3 lib
[work@mars ~]# sudo pip3 install ipykernel numpy joblib keras tensorflow matplotlib pydot

#Jupyter注册python3内核
[work@mars jupyter]$ python3 -m ipykernel install --user
Installed kernelspec python3 in /home/work/.local/share/jupyter/kernels/python3

刷新jupyter,查看可选的kernel,会多出python3选项:

欢迎关注下方“非著名资深码农“公众号进行交流~

发表评论

邮箱地址不会被公开。