配置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 这个路径下。
天下难事,必作于易;天下大事,必作于细