1. 程式人生 > 實用技巧 >使用Jupyter定製個性化python

使用Jupyter定製個性化python

現階段python在人工智慧及資料分析中得到了很多的實踐成果。而python的編輯器也有很多種,如:pychram、N++、jupyter……其中jupyter以web的形式來進行編輯的工具。接下來講下如何使用睿江雲服務來部署jupyter這強大的工具。

一、環境配置

1.centeos7

2.python3

二、安裝jupyter notebook

安裝jupyter
安裝Jupyter Notebook
    通過pip安裝Jupyter Notebook
#安裝jupyter notebook
    python3 -m pip install jupyter
#安裝完會在python3的包管理器,建立一個軟連線以便在任何地方都可以直接執行
    ln 
-s /usr/local/python3/bin/jupyter /usr/bin/jupyter 通過jupyter notebook命令啟動Jupyter伺服器,驗證是否安裝成功 [root@instance-hrnebyqu bin]# jupyter notebook --allow-root [I 11:26:22.273 NotebookApp] JupyterLab beta preview extension loaded from /root/anaconda3/lib/python3.6/site-packages/jupyterlab [I 11:26:22.273 NotebookApp] JupyterLab application directory is
/root/anaconda3/share/jupyter/lab [I 11:26:22.277 NotebookApp] Serving notebooks from local directory: /root/ipython

至此,Jupyter Notebook安裝成功。

配置外部訪問
    關閉防火牆(CentOS7)
        systemctl stop firewalld.service
        systemctl disable firewalld.service
    生成Jupyter Notebook配置檔案
         jupyter notebook 
--generate-config 通過 ipython 建立登入密碼:(這個要進入python3的bin目錄執行) In [2]: passwd() Enter password: Verify password: Passwords do not match. Enter password: Verify password: Out[2]: 'sha1:b79414f2844a:27a3bd36f0d79a1e51664e21e75559b3c5554db4' 編輯生成的配置檔案 /root/.jupyter/jupyter_notebook_config.py,並在檔案頭新增如下配置資訊: [root@instance-hrnebyqu bin]# vim /root/.jupyter/jupyter_notebook_config.py c.NotebookApp.ip='0.0.0.0' #監聽所有的地址 c.NotebookApp.password = u'sha1:153a389b3933:9e8c3bcaf7690cf46931f81c21e39753d3a1696d' #就是前面生成的密碼 c.NotebookApp.open_browser = False c.NotebookApp.port =8888 #指定埠 c.NotebookApp.notebook_dir = "/root/ipython" #jupyter的工作目錄

通過瀏覽器訪問地址:

http://ipaddress:8888/

注意:這邊的密碼是加密前的面而不是‘sha1….’

三、拓展

在jupyter介面直接安裝第三方包或者執行命令列命令,記得加上感嘆號,英文的!pip install jsonpath。

在jupyter中安裝檢視解除安裝第三方包:

import pip
def pip_install(package):
    pip.main(['install', package])
def pip_list():
    print(pip.main(['list']))
def pip_uninstall(package):
        pip.main(['uninstall', package])

以上是jupyter的安裝及配置的簡單講解,之後可以安裝一個屬於自己的雲端python編輯器。