您的位置:

jupyter目录详解

一、jupyter目录在哪

jupyter目录由jupyter notebook管理,它是一个基于web的交互式计算环境,支持运行各种编程语言并以notebook的形式组织数据、代码、文本和图像。在安装jupyter notebook后,启动jupyter notebook,在浏览器中打开notebook主界面,在右上角点击New按钮,可以新建一个notebook,它的默认工作目录就是当前系统用户的home目录。

二、怎么显示jupyter目录

jupyter notebook默认不显示目录,只显示notebook文件。如果需要在notebook中显示目录,可以使用jupyter_contrib_nbextensions提供的Tree View插件。这个插件可以在侧边栏中显示notebook文件和目录。安装这个插件需要使用pip命令:

!pip install jupyter_contrib_nbextensions
!jupyter contrib nbextension install --user
!jupyter nbextension enable treeview/main

安装完后,在jupyter notebook的主菜单中会多出一个Nbextensions选项卡,选择TreeView选项,在右侧勾选Tree和Collapsible headings两个选项,保存设置,重新加载notebook,就能在侧边栏中看到目录了。

三、jupyter目录树

jupyter目录树是指将某个目录下的notebook文件以树形结构展示在notebook中。有时候项目中的notebook文件会很多,如果需要选择某个文件进行编辑,就需要不断地在notebook列表中滚动,非常不便。jupyter_contrib_nbextensions提供了Tree Filter、Variable Inspector和Execute Time插件可以实现在notebook中显示目录树。安装这三个插件的步骤和TreeView插件类似,安装命令如下:

!pip install jupyter_contrib_nbextensions
!jupyter contrib nbextension install --user
!jupyter nbextension enable tree_filter/main
!jupyter nbextension enable varInspector/main
!jupyter nbextension enable execute_time/ExecuteTime

安装完后,在jupyter notebook的主菜单中进入Nbextensions选项卡,在Tree Filter选项中可以输入notebook名称或作者进行过滤,Variable Inspector可以查看当前notebook中的变量和函数,Execute Time可以显示每个单元格的执行时间。

四、jupyter目录怎么批量删除

jupyter目录支持批量删除的方式有多种,下面两种方式比较容易实现:

1、使用os模块

import os
import glob
from pathlib import Path

# 指定目录
folder_path = Path('./目录名称')

# 获取所有的.ipynb文件路径
file_list = glob.glob(str(folder_path / '*.ipynb'))

# 删除所有的.ipynb文件
for file_path in file_list:
    os.remove(file_path)

2、使用IPython.display模块和IPython.lib.backgroundjobs模块

from IPython.display import display, Javascript
from IPython.lib.backgroundjobs import BackgroundJobManager

def delete_files_local(filter):
    job_manager = BackgroundJobManager()
    cmd = f"""!find ./ -name '{filter}' -exec rm "{{}}" \;"""
    job_manager.new_job(cmd).start()

delete_files_local('*.ipynb')

五、jupyter目录怎么设置

jupyter目录的设置可以通过jupyter_notebook_config.py文件进行配置。该文件通常位于~/.jupyter/目录下。如果该文件不存在,可以使用以下命令生成:

jupyter notebook --generate-config

可以在该文件中添加自定义设置,如下是一些比较常用的配置:

c.NotebookApp.ip = '*'
c.NotebookApp.port = 8888
c.NotebookApp.open_browser = False
c.NotebookApp.notebook_dir = '/home/user/path/to/notebook'

其中,c.NotebookApp.ip可以设置jupyter notebook的IP地址(默认为localhost);c.NotebookApp.port可以设置jupyter notebook的端口号(默认为8888);c.NotebookApp.open_browser可以设置是否在启动jupyter notebook时自动打开浏览器(默认为True);c.NotebookApp.notebook_dir可以设置jupyter notebook的主目录。

六、jupyter目录怎么打

jupyter目录可以在jupyter notebook中打开,也可以在命令行中使用浏览器打开。如果需要在命令行中打开jupyter目录,可以使用以下命令:

jupyter notebook --no-browser --port 8888

该命令将在本地启动jupyter notebook,并监听8888端口。如果需要在其他计算机中打开jupyter目录,可以使用ssh隧道,具体方法如下:

1、在远程计算机中启动jupyter notebook,并指定监听本地IP地址的某个端口,如8888

jupyter notebook --ip=127.0.0.1 --port=8888

2、在本地计算机中使用ssh隧道将指定的端口映射到本地计算机的某个端口,如8889

ssh -N -f -L localhost:8889:localhost:8888 user@remote_host

3、在本地计算机的浏览器中访问localhost:8889,即可访问远程计算机上的jupyter目录。

七、jupyter目录名称无效

jupyter目录名称无效是因为非法字符或与系统保留关键字冲突。jupyter notebook规定目录名称只能使用字母、数字、下划线和连字符,不能以连字符开头或结尾。

八、jupyter目录名称无效是怎么回事

如果使用了非法字符或系统保留关键字,jupyter notebook会提示目录名称无效。以下是一些不合法的目录名称示例:

my notebook # 包含空格
my/notebook # 包含斜杠
my-notebook- # 以连字符结尾
-delete # 以连字符开头

九、jupyter目录二级标题打不出

如果在jupyter notebook中使用markdown语法添加标题时,发现二级标题打不出。这可能是因为在标题前没有使用空格。正确的二级标题语法应该如下:

## 二级标题

十、jupyter目录不显示选取

如果jupyter notebook中的目录不显示选取,则可以尝试使用以下命令更新jupyter_contrib_nbextensions:

pip install --upgrade jupyter_contrib_nbextensions

更新完成后,重启jupyter notebook即可。