python3.6安裝
- 下載python安裝包,這里下載的最新的3.6.1版本
https://www.python.org/ftp/python/3.6.1/ - 將安裝包上傳到服務器并解壓
tar zxvf Python-3.6.1.tgz
- 安裝python
cd Python-3.6.1
./configure --prefix=/usr/local/python-3.6.1 #重要,指定python的安裝路徑,可以自己設置。
make
sudo make install
- 修改python的軟鏈接 (建立軟鏈接,變為全局)
sudo ln -s /usr/local/python-3.6.1/bin/python3.6 /usr/bin/python
- 查看python版本,發現已經改變
python
ipython安裝
- 下載ipython,并上傳到服務器
http://archive.ipython.org/release/6.0.0/ - 解壓
tar -zxvf ipython-6.0.0.tar.gz
- 進入解壓的ipython目錄并執行如下命令進行安裝
python setup.py install
- 進行鏈接
ln -s /usr/local/python-3.6.1/bin/ipython /usr/sbin/ipython
- 檢查ipython是否安裝成功
ipython
此時發現提示說有模板缺失,使用pip進行安裝。
pip install traitlets
再執行ipython進行檢驗,發現還是某個模板缺失
繼續用pip進行安裝,知道執行ipython時出現如下界面,代表安裝成功。
Jupyter Notebook安裝
Jupyter Notebook(此前被稱為 IPython notebook)是一個交互式筆記本,支持運行 40 多種編程語言。Notebook是一個數據分析和編寫代碼的好工具。它的核心在于展示與快速迭代。
摘自: 知乎為什么使用jupyter?
看完知乎的這個回答會對jupyter有個大概的認知,接下來進行安裝。
- 安裝jupyter notebook
pip install jupyter notebook
- 啟動notebook
jupyter notebook
此時報錯,不建議用root運行啟動命令:
[I 16:23:40.195 NotebookApp] Writing notebook server cookie secret to /root/.local/t
[C 16:23:40.213 NotebookApp] Running as root is not recommended. Use --allow-root t.
解決方法:
- 修改配置文件,執行jupyter notebook --generate-config即可初始化配置文件來,但是這里要加入--allow-root才行
[root@localhost ~]# jupyter notebook --generate-config --allow-root
Writing default config to: /root/.jupyter/jupyter_notebook_config.py
- 創建一個密碼:[這樣就不用每次復制URL地址]
[root@localhost ~]# ipython
Python 3.6.1 (default, May 25 2017, 16:49:43)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.0.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:f6ac161e9215:dc0eb8c8d43b74e32bb03db161e3261ea5d7c297'
將這里的 ```
'sha1:f6ac161e9215:dc0eb8c8d43b74e32bb03db161e3261ea5d7c297'
* 修改配置文件中的IP地址、工作目錄、并添加一個認證密碼:
[root@localhost .jupyter]# vim /root/.jupyter/jupyter_notebook_config.py
修改權限
c.NotebookApp.allow_root = False
去掉行注釋,并修改成True即可解決root權限運行的問題。
設置,外部可訪問
c.NotebookApp.ip = 'localhost'
去掉注釋,并把localhost改成0.0.0.0,這樣就可以外部訪問了,默認只有在本機可以訪問的;
c.NotebookApp.ip = '0.0.0.0'
設置notebook的工作目錄
c.NotebookApp.notebook_dir = u''
改成如下,這樣就會默認把notebook上創建的文件保存到指定目錄下;需要事先創建。
c.NotebookApp.notebook_dir = u'/opt/jupyter'
加入密碼
c.NotebookApp.password = u''
加入上面創建的密碼:
c.NotebookApp.password = u'sha1:f6ac161e9215:dc0eb8c8d43b74e32bb03db161e3261ea5d7c297'
3. 進入notebook界面
再次執行啟動命令,出現如下信息,表示成功
[root@localhost .jupyter]# jupyter-notebook
[I 18:09:58.194 NotebookApp] Serving notebooks from local directory: /opt/jupyter
[I 18:09:58.194 NotebookApp] 0 active kernels
[I 18:09:58.194 NotebookApp] The Jupyter Notebook is running at:
http://0.0.0.0:8888/bookApp]
在瀏覽器輸入如下網址:http://你的ip:8888
可以看到如下界面:

**參考:**
[官方文檔](https://jupyter.readthedocs.io/en/latest/install.html)
[centos7安裝notebook 5.0.0的方法](https://www.58jb.com/html/146.html)