配置jupyter notebook網頁瀏覽


上一篇博文已經介紹安裝了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.生成配置文件

[python@master2 ~]$ 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.重新啟動:

[python@master2 ~]$ 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 這個路徑下。


免責聲明!

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



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