虛擬機搭建jupyter notebook服務
- 搭建前提:虛擬機中裝有linux系統(如centos,ubuntu等)
1. 下載并安裝anaconda
1.1 下載anaconda(下載緩慢,慢慢等)
wget https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh
![[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-yTWXBIZg-1635319295829)(C:\Users\danxibao\AppData\Roaming\Typora\typora-user-images\image-20211027140959986.png)]](https://img.uj5u.com/2021/10/28/278529280909261.png)
1.2 進入自己的安裝目錄,安裝anaconda
bash Anaconda3-5.2.0-Linux-x86_64.sh
接著按Enter和yes就完事,完成安裝
2. 環境配置
2.1 查看anaconda的bin目錄的地址
pwd #進入bin目錄下查看地址
![[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-BQE47Rzd-1635319295834)(C:\Users\danxibao\AppData\Roaming\Typora\typora-user-images\image-20211027142655011.png)]](https://img.uj5u.com/2021/10/28/278529280909262.png)
2.2 添加PATH到/root/.bashrc檔案中
![[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-EACT0JEk-1635319295840)(C:\Users\danxibao\AppData\Roaming\Typora\typora-user-images\image-20211027143223721.png)]](https://img.uj5u.com/2021/10/28/278529280909263.png)
2.3 驗證結果
conda --version
![[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-8FLizNfO-1635319295844)(C:\Users\danxibao\AppData\Roaming\Typora\typora-user-images\image-20211027143429800.png)]](https://img.uj5u.com/2021/10/28/278529280909264.png)
3. conda環境管理
3.1 創建虛擬環境
conda create -n name python=x.x
![[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-l0KUTfiu-1635319295847)(C:\Users\danxibao\AppData\Roaming\Typora\typora-user-images\image-20211027143730801.png)]](https://img.uj5u.com/2021/10/28/278529280909265.png)
3.2 使用activate激活環境
source activate python3.6.5
![[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-8AorJaIq-1635319295849)(C:\Users\danxibao\AppData\Roaming\Typora\typora-user-images\image-20211027143952392.png)]](https://img.uj5u.com/2021/10/28/278529280909266.png)
3.3 查看已有的虛擬環境
![[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-vrDe9Gwd-1635319295851)(C:\Users\danxibao\AppData\Roaming\Typora\typora-user-images\image-20211027144314824.png)]](https://img.uj5u.com/2021/10/28/278529280909267.png)
4. jupyter配置
4.1 生成組態檔
jupyter notebook --generate-config --allow-root
4.2 生成登錄密碼
jupyter notebook password
![[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-hxEO8SrL-1635319295852)(C:\Users\danxibao\AppData\Roaming\Typora\typora-user-images\image-20211027145119217.png)]](https://img.uj5u.com/2021/10/28/278529280909268.png)
4.3 設定監聽地址
sed -ie "s/#c.NotebookApp.ip = 'localhost'/c.NotebookApp.ip = '0.0.0.0'/g" ~/.jupyter/jupyter_notebook_config.py
4.4 設定監聽埠
sed -ie 's/#c.NotebookApp.port = 8888/c.NotebookApp.port = 3030/g' ~/.jupyter/jupyter_notebook_config.py
5. 啟動jupyter
5.1 啟動服務
jupyter notebook --allow-root &

5.2 后臺運行服務
nohup jupyter notebook --allow-root > jupyter.log 2>&1 &

6. 內網穿透
ssh -R 80:127.0.0.1:3030 ssh.localhost.run
![[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-APauVdYQ-1635319295860)(C:\Users\danxibao\AppData\Roaming\Typora\typora-user-images\image-20211027150120948.png)]](https://img.uj5u.com/2021/10/28/2785292809092611.png)
7. 驗證
- 輸入上述地址進行驗證
![[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-pk7nagZp-1635319295862)(C:\Users\danxibao\AppData\Roaming\Typora\typora-user-images\image-20211027151048704.png)]](https://img.uj5u.com/2021/10/28/2785292809092612.png)

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/339307.html
標籤:其他
