配置jupyter notebook網頁瀏覽
阿新 • • 發佈:2019-01-11
上一篇博文已經介紹安裝了Anaconda3:https://www.cnblogs.com/hello-wei/p/10233192.html
jupyter notebook
[I 11:33:11.578 NotebookApp] JupyterLab extension loaded from /home/python/anaconda3/lib/python3.7/site-packages/jupyterlab
[I 11:33:11.579 NotebookApp] JupyterLab application directory is /home/python/anaconda3/share/jupyter/lab
[I 11:33:11.581 NotebookApp] 啟動notebooks 在本地路徑: /home/python/jupyter_notebook
[I 11:33:11.581 NotebookApp] 本程式執行在: http://localhost:8888/
一直進不去進不去網頁
NotebookApp] No web browser found: could not locate runnable browser.
解決方法:
1.設定密碼獲得祕鑰
python@master2 ~]$ ipython Python 3.7.1 (default, Dec 14 2018, 19:28:38) Type 'copyright', 'credits' or 'license' for more information IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.In [1]: from IPython.lib import passwd In [2]: passwd() Enter password: Verify password: Out[2]: 'sha1:44b9b4ac9989:b819a8dca76aa86c2e1676ec86c8f59fb4e51802'
2.生成配置檔案
[[email protected] ~]$ jupyter notebook --generate-config Writing default config to: /home/python/.jupyter/jupyter_notebook_config.py
3.修改配置檔案內容
c.NotebookApp.ip = '192.168.1.250' c.NotebookApp.allow_root = True c.NotebookApp.open_browser = False c.NotebookApp.port = 8888 c.NotebookApp.password = 'sha1:...' #輸入上面加密後得到的密文 c.ContentsManager.root_dir = '/home/python/jupyter_notebook'
4.重新啟動:
[[email protected] ~]$ jupyter notebook [I 11:33:11.578 NotebookApp] JupyterLab extension loaded from /home/python/anaconda3/lib/python3.7/site-packages/jupyterlab [I 11:33:11.579 NotebookApp] JupyterLab application directory is /home/python/anaconda3/share/jupyter/lab [I 11:33:11.581 NotebookApp] 啟動notebooks 在本地路徑: /home/python/jupyter_notebook [I 11:33:11.581 NotebookApp] 本程式執行在: http://192.168.1.250:8888/ [I 11:33:11.581 NotebookApp] 使用control-c停止此伺服器並關閉所有核心(兩次跳過確認). [I 11:33:23.082 NotebookApp] 302 GET / (192.168.1.1) 1.61ms
輸入網址:http://192.168.1.250:8888/
密碼:****
進入頁面如下顯示:
然後就可以測試:
import _thread from time import sleep import datetime loops=[4,2] def date_time_str(): return datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') def loop(n_loop,n_sec,lock): print('執行緒(',n_loop,') 開始執行:',date_time_str(),',先休眠(',n_sec,')秒') sleep(n_sec) print('執行緒(',n_loop,')休眠結束,結束於:',date_time_str()) lock.release() def main(): print('---所有執行緒開始執行...') locks=[] n_loops=range(len(loops)) for i in n_loops: lock=_thread.allocate_lock() lock.acquire() locks.append(lock) for i in n_loops: _thread.start_new_thread(loop,(i,loops[i],locks[i])) for i in n_loops: while locks[i].locked(): pass print('---所有執行緒執行結束:',date_time_str()) if __name__=='__main__': main()
可以儲存程式碼塊,對應的程式碼在:/home/python/jupyter_notebook 這個路徑下。