Python3.7 + jupyter安装(CentOS6.5)
方法一(anaconda):
- anaconda是一个开源的Python发行版本
- 包含conda,python等大量的科学包以及依赖
- 优点:开箱即用,无需自己解决兼容问题
- 缺点:比较庞大,安装包600M,解压出来3.5G
下载地址:https://www.anaconda.com/distribution/#download-section
- 下载安装脚本(600M)
- 执行交互式脚本,自定义安装目录
- 最后不要执行初始化文件,让它单独存放,以免干扰系统原生的python环境
#安装脚本
[root@app1 local]# ls -lh Anaconda3-2018.12-Linux-x86_64.sh
-rw-r--r-- 1 root root 653M Mar 5 15:55 Anaconda3-2018.12-Linux-x86_64.sh
#安装后的目录
[root@app1 local]# ll -h /data/anaconda3/
total 208K
drwxr-xr-x 4 root root 12K Mar 5 18:39 bin
drwxr-xr-x 2 root root 4.0K Mar 5 16:21 compiler_compat
drwxr-xr-x 2 root root 20K Mar 5 16:23 conda-meta
drwxr-xr-x 3 root root 4.0K Mar 5 16:22 doc
drwxr-xr-x 2 root root 4.0K Mar 5 16:23 envs
drwxr-xr-x 7 root root 4.0K Mar 5 16:23 etc
drwxr-xr-x 38 root root 12K Mar 5 16:23 include
drwxr-xr-x 23 root root 36K Mar 5 16:23 lib
drwxr-xr-x 4 root root 4.0K Mar 5 16:22 libexec
-rw-r--r-- 1 root root 5.7K Dec 20 13:45 LICENSE.txt
drwxr-xr-x 3 root root 4.0K Mar 5 16:21 man
drwxr-xr-x 65 root root 4.0K Mar 5 16:22 mkspecs
drwxr-xr-x 2 root root 4.0K Mar 5 16:22 phrasebooks
drwxr-xr-x 278 root root 36K Mar 5 16:20 pkgs
drwxr-xr-x 26 root root 4.0K Mar 5 16:22 plugins
drwxr-xr-x 25 root root 4.0K Mar 5 16:22 qml
drwxr-xr-x 2 root root 4.0K Mar 5 16:22 resources
drwxr-xr-x 2 root root 4.0K Mar 5 16:22 sbin
drwxr-xr-x 31 root root 4.0K Mar 5 16:23 share
drwxr-xr-x 3 root root 4.0K Mar 6 08:32 ssl
drwxr-xr-x 3 root root 12K Mar 5 16:22 translations
drwxr-xr-x 3 root root 4.0K Mar 5 16:22 var
-rw-r--r-- 1 root root 0 Mar 5 16:31 vscode_inst.py.log
drwxr-xr-x 3 root root 4.0K Mar 5 16:21 x86_64-conda_cos6-linux-gnu
#启动jupyter
/data/anaconda3/bin/jupyter notebook --ip=0.0.0.0 --port=8889 --allow-root --no-browser
方法二(源码安装Python3.7,pip3安装jupyter)
- 优点:轻量级安装,需要什么装什么,撇除多余的东西
- 缺点:需要自己解决依赖包和兼容问题
- 问题一:Python3.7已不支持openssl-1.0.1及以下版本,所以无法编译ssl模块,从而导致pip3无法使用
- 问题二:pip3安装jupyter时默认安装的tornado版本过高导致jupyter无法正常使用
- 以上问题是笔者碰到的主要问题,其余依赖较容易解决,在此不详述
- 官网下载最新版Python(目前是Python3.7.2)
- 解决普通依赖包
编译前的准备
yum -y install zlib* #解决编译zip报错
yum -y install readline-devel #解决python3无法使用ctrl+l清屏问题
yum -y install openssl-devel #解决安装后pip3无法使用ssl的问题
yum -y install libffi-devel #解决无法编译_ctypes模块问题
- 解决openssl问题
#系统本来的openssl包,这个版本已不被Python3.7支持,直接编译无法通过
[root@app1 local]# yum list installed | grep openssl
openssl.x86_64 1.0.1e-57.el6 @base
openssl-devel.x86_64 1.0.1e-57.el6 @base
- openssl和openssl-devel是什么关系 参考 https://blog.csdn.net/devalone/article/details/82459276
- 解决办法:源码安装被Python3.7支持的openssl包
下载地址:https://www.openssl.org/source/
[root@app1 local]# ls -lh openssl-1.0.2r.tar.gz
-rw-r--r-- 1 root root 5.2M Mar 5 20:57 openssl-1.0.2r.tar.gz
./config
make
make test
make install
#本次安装在这个目录
[root@app1 local]# ls -lh /usr/local/ssl
total 52K
drwxr-xr-x 2 root root 4.0K Mar 6 08:02 bin
drwxr-xr-x 2 root root 4.0K Mar 5 19:03 certs
drwxr-xr-x 3 root root 4.0K Mar 6 08:02 include
drwxr-xr-x 4 root root 4.0K Mar 6 08:34 lib
drwxr-xr-x 6 root root 4.0K Mar 6 08:01 man
drwxr-xr-x 2 root root 4.0K Mar 6 08:02 misc
-rw-r--r-- 1 root root 11K Mar 6 08:02 openssl.cnf
-rw-r--r-- 1 root root 11K Mar 5 19:03 openssl.cnf.dist
drwxr-xr-x 2 root root 4.0K Mar 5 19:03 private
- 或者安装libressl 参考 https://blog.csdn.net/devalone/article/details/82459276 (未尝试)
- 编译安装Python3.7
#编译前准备
vim /usr/local/Python-3.7.2/Modules/Setup #修改编译时的ssl配置
SSL=/usr/local/ssl #openssl安装目录
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
#配置、编译、安装
./configure --prefix=/usr/local/ --with-openssl=/usr/local/ssl/
make
make install
- pip3安装jupyter
pip3 install --upgrade pip
pip3 install jupyter
- 启动jupyter
jupyter notebook --ip=0.0.0.0 --allow-root --no-browser
此时如果报错无法导入sqlite3,确保系统安装了sqlite,没有的话需要安装,然后重新编译Python3.7
[root@app1 ~]# yum list installed | grep sqlite
qt-sqlite.x86_64 1:4.6.2-26.el6_4 @anaconda-CentOS-201311272149.x86_64/6.5
sqlite.x86_64 3.6.20-1.el6_7.2 @base
sqlite-devel.x86_64 3.6.20-1.el6_7.2 @base
- 浏览器打开IP:8888,启用python3时发现无法连接服务,这就是tornado版本过高,使用pip3重装tornado即可
[root@app1 ~]# pip3 uninstall tornado
Uninstalling tornado-6.0.1:
Would remove:
/usr/local/lib/python3.7/site-packages/tornado-6.0.1-py3.7.egg-info
/usr/local/lib/python3.7/site-packages/tornado/*
Proceed (y/n)? y
Successfully uninstalled tornado-6.0.1
[root@app1 ~]# pip3 install tornado==5.1.1
Collecting tornado==5.1.1
Downloading https://files.pythonhosted.org/packages/e6/78/6e7b5af12c12bdf38ca9bfe863fcaf53dc10430a312d0324e76c1e5ca426/tornado-5.1.1.tar.gz (516kB)
100% |████████████████████████████████| 522kB 10.0MB/s
Installing collected packages: tornado
Running setup.py install for tornado ... done
Successfully installed tornado-5.1.1