centos6.4安裝 jupyter-notebook


自上次發布了文章后有些網友就說不能實現效果,根據自己的實驗發現確實有此事,那是因為版本的變化問題。這次基於yum倉庫里的jupyter notebook 5.0.0版本實現;

 

 系統:最小化安裝[習慣性] 

關閉防火牆:

  1. systemctl stop firewalld && systemctl disable firewalld 

禁用SELINUX:

  1. [root@jupyter ~]# sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config 
  2. [root@jupyter ~]# setenforce 0 

 添加EPLE源:

  1. rpm -ivh http://mirrors.yun-idc.com/epel/epel-release-latest-7.noarch.rpm 

安裝部分可能用到的依賴包: 

 

  1. yum install vim openssl-devel readline-devel python-devel python-pip -y  
 Python-3.5.2 編譯安裝:

 

  1. tar xf Python-3.5.2.tgz  
  2. cd Python-3.5.2  
  3. ./configure --prefix=/usr/local/python-3.5.2  
  4. make && make install  
  5.   
  6. #創建一個軟連接:  
  7. ln -sf /usr/local/python-3.5.2/bin/python3 /usr/bin/python3  
  8. ln -sf /usr/local/python-3.5.2/bin/pip3 /usr/bin/pip3 
這樣就安裝完Python3了;
 
#接下來安裝jupyter:

 

  1. pip install jupyter   //這命令默認使用的是Python2.7.5版本安裝;  

安裝完后即可以啟動:jupyter-notebook  

 

  1. jupyter-notebook  

 如果在啟動的時候提示,說明默認不建議使用root來運行,不過我們可以配置文件修改,接下來會介紹如何修改;

 

  1. [C 15:03:06.778 NotebookApp] Running as root is not recommended. Use --allow-root to bypass.  
 在上一次的版本中直接執行jupyter notebook --generate-config即可初始化配置文件來,但是新版的要加入--allow-root才行;

 

  1. [root@pydev ~]# jupyter notebook --generate-config --allow-root 
  2. Writing default config to: /root/.jupyter/jupyter_notebook_config.py  
 

創建一個密碼:[這樣就不用每次復制URL地址] 

 

  1. [root@jupyter ~]# ipython  
  2. Python 2.7.5 (default, Nov  6 2016, 00:28:07)   
  3. Type "copyright", "credits" or "license" for more information.  
  4.   
  5. IPython 5.3.0 -- An enhanced Interactive Python.  
  6. ?         -> Introduction and overview of IPython's features.  
  7. %quickref -> Quick reference.  
  8. help      -> Python's own help system.  
  9. object?   -> Details about 'object', use 'object??' for extra details.  
  10.   
  11. In [1]: from notebook.auth import passwd  
  12.   
  13. In [2]: passwd()  
  14. Enter password:   
  15. Verify password:   
  16. Out[2]: 'sha1:da874cad4309:4104089e5ef97c8fcbe69c2ac7d6a1071ca50a40' 
 
 修改配置文件中的IP地址、工作目錄、並添加一個認證密碼:

 

  1. 62 #c.NotebookApp.allow_root = False  
  2. 去掉62行的注釋,並修改成True即可解決root權限運行的問題。  
  3. 163 #c.NotebookApp.ip = 'localhost'  
  4. 去掉注釋,並把localhost改成0.0.0.0,這樣就可以外部訪問了,默認只有在本機可以訪問的;  
  5. 163 c.NotebookApp.ip = '0.0.0.0'  
  6.   
  7. 203 #c.NotebookApp.notebook_dir = u''  
  8. 改成如下,這樣就會默認把notebook上創建的文件保存到指定目錄下;需要事先創建。   
  9. 203 c.NotebookApp.notebook_dir = u'/opt/jupyter'  
  10.   
  11.   
  12. 218 #c.NotebookApp.password = u''  
  13. 加入上面創建的密碼:  
  14. 218 c.NotebookApp.password = u'sha1:da874cad4309:4104089e5ef97c8fcbe69c2ac7d6a1071ca50a40'  
 
這里就是行號有所變化;根據關鍵字查詢即可;

保存,重新運行程序: 

 

  1. [root@jupyter~]# jupyter-notebook   
  2. [I 15:20:53.313 NotebookApp] Serving notebooks from local directory: /opt/jupyter  
  3. [I 15:20:53.313 NotebookApp] 0 active kernels   
  4. [I 15:20:53.313 NotebookApp] The Jupyter Notebook is running at: http://0.0.0.0:8888/  
  5. [I 15:20:53.313 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).  
  6. [W 15:20:53.313 NotebookApp] No web browser found: could not locate runnable browser.  

URL地址:10.0.10.253:8888

密碼:123456 

 不過在查看版本的時候還是有個問題,就是切換了python版后,使用命令還是一樣顯示為python2.7.5

 驗證:輸入命令:netstat -ntlp

[root@localhost centos]$  netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1980/dnsmasq tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1598/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1601/cupsd tcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN 18997/python tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1874/master tcp6 0 0 :::111 :::* LISTEN 1/systemd tcp6 0 0 :::22 :::* LISTEN 1598/sshd tcp6 0 0 ::1:631 :::* LISTEN 1601/cupsd tcp6 0 0 :::8888 :::* LISTEN 18997/python tcp6 0 0 ::1:25 :::* LISTEN 1874/master

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM