zoukankan      html  css  js  c++  java
  • 初识jupyter notebook

    初学笔记

    常用命令表

    1. 启动:jupyter notebook --port 9999
    2. 帮助:jupyter notebook -h
    3. 加载:
      HTML源码:%load URL
      本地Python:%load 本地绝对地址
    4. 运行本地Python: %run 本地绝对地址 或 !python3 本地绝对地址 或 !python 本地绝对地址
    5. 当前位置:!pwd 或 %pwd
    6. 在code行中使用shell命令:!shell命令 例如: !lm
    7. 隐藏输入输出单元格
      以下两块code选择一个放置在第一个单元格中: 但对md不适用
    from IPython.display import display  
    from IPython.display import HTML  
    import IPython.core.display as di # Example: di.display_html('<h3>%s:</h3>' % str, raw=True)  
    # 这行代码的作用是:当文档作为HTML格式输出时,将会默认隐藏输入单元格。  
    di.display_html('<script>jQuery(function() {if (jQuery("body.notebook_app").length == 0) { jQuery(".input_area").toggle(); jQuery(".prompt").toggle();}});</script>', raw=True)  
    # 这行代码将会添加“Toggle code”按钮来切换“隐藏/显示”输入单元格。   
    di.display_html('''<button onclick="jQuery('.input_area').toggle(); jQuery('.prompt').toggle();">Toggle code</button>''', raw=True)  
    
    from IPython.display import HTML
    HTML('''<script>
    code_show=true; 
    function code_toggle() {
     if (code_show){
     $('div.input').hide();
     } else {
     $('div.input').show();
     }
     code_show = !code_show
    } 
    $( document ).ready(code_toggle);
    </script>
    <form action="javascript:code_toggle()"><input type="submit" value="Click here to toggle on/off the raw code."></form>''')
    

    安装、初始配置、初始启动

    1. 基础:有python3且pip较新、Windows10
    2. 安装命令:(最好先配置个虚拟环境env)pip install jupyter(慢慢等,有点长)
    3. 初始启动:jupyter notebook(默认端口启动,自动打开浏览器)、jupyter notebook --port 9999(自定义端口9999启动,自动打开游览器)、jupyter notebook --no-browser(不自动打开浏览器)
    4. 帮助命令:jupyter notebook --help 、 jupyter notebook -h
    5. 初始化默认配置文件:jupyter notebook --generate-config(会显示文件目录,在user/<you>/.jupyter/中)(当有要求输入[Y/N]时,输入Y就会以默认配置覆盖已配置的文件,故请输入 N 保留已配置的信息)
    6. 配置工作根目录:打开上述配置文件,搜索“c.NotebookApp.notebook_dir”关键字,替换其值为你自定义的工作根目录的绝对地址(即:把地址放进引号中,注意英文半角及地址分隔符“”和“/”的区别),然后取消注释(即:删除行首的“#”),保存文件
    7. 重新启动:命令同上,浏览器内显示自定义根目录

    扩展

    conda扩展

    1. 安装conda,参考:https://www.cnblogs.com/dgz-bb1304/p/13830425.html

    2. 在conda某一需要jupyter notebook的python环境中执行命令:conda install nb_conda
      然后启动jupyter notebook打开浏览器查看是否有conda界面

    3. 卸载命令:conda remove nb_conda(需要在那个环境里执行)

    markdown扩展

    1. 安装命令:在conda的某一python环境里:conda install -c conda-forge jupyter_contrib_nbextensions
      然后启动jupyter notebook打开浏览器查看nbextensions

    2. 如果 不小心把nbextentions按钮弄没了但安装的 jupyter_contrib_nbextensions还在,就启动jupyter,打开链接进行选择几项即可http://localhost:8888/nbextensions?nbextension=toc2/main (有特殊标识的项)

    3. 打开nbextensions,选择Table of Contents (2)项

    4. 选择一个文件,打开之后选择编辑栏按钮的右侧一个列表状的按钮,即可看到文件左侧的树形目录

    参考链接:https://www.jianshu.com/p/91365f343585

    声明:

    增删有风险,操作要谨慎;凡操作失误,导致的损失,与本人无关;实施操作前请做好安全措施。
    谢谢关注!

  • 相关阅读:
    POJ 2348 Euclid's Game【博弈】
    POJ 2484 A Funny Game【博弈】
    HDU 4193 Non-negative Partial Sums【单调队列】
    占坑补题
    Codeforces 658D Bear and Polynomials【数学】
    Codeforces 658C Bear and Forgotten Tree 3【构造】
    Codeforces 658B Bear and Displayed Friends【set】
    POJ 1704 Georgia and Bob【博弈】
    1001. A+B Format

  • 原文地址:https://www.cnblogs.com/dgz-bb1304/p/13830827.html
Copyright © 2011-2022 走看看