Python3.7 + jupyter安裝(CentOS6.5)

Python3.7 + jupyter安裝(CentOS6.5)

方法一(anaconda):
  • anaconda是一個開源的Python發行版本
  • 包含conda,python等大量的科學包以及依賴
  • 優勢:開箱即用,無需本身解決兼容問題
  • 缺點:比較龐大,安裝包600M,解壓出來3.5G

下載地址:https://www.anaconda.com/distribution/#download-sectionpython

  1. 下載安裝腳本(600M)
  2. 執行交互式腳本,自定義安裝目錄
  3. 最後不要執行初始化文件,讓它單獨存放,以避免干擾系統原生的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沒法正常使用
  • 以上問題是筆者碰到的主要問題,其他依賴較容易解決,在此不詳述
  1. 官網下載最新版Python(目前是Python3.7.2)
  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模塊問題 
  1. 解決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 
  • 解決辦法:源碼安裝被Python3.7支持的openssl包

下載地址:https://www.openssl.org/source/linux

[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 
  1. 編譯安裝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 
  1. pip3安裝jupyter
pip3 install --upgrade pip pip3 install jupyter 
  1. 啓動jupyter
jupyter notebook --ip=0.0.0.0 --allow-root --no-browser 

此時若是報錯沒法導入sqlite3,確保系統安裝了sqlite,沒有的話須要安裝,而後從新編譯Python3.7git

[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 
  1. 瀏覽器打開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
相關文章
相關標籤/搜索