Jupyter安装
1. 使用记录
Section titled “1. 使用记录”- 安装
conda install jupyter notebook-
在指定目录启动 jupyter
- 临时启动
Terminal window jupyter notebook --notebook-dir='D://demo' #临时- 永久配置
Terminal window jupyter notebook --generate-configvim ~/.jupyter/jupyter_notebook_config.pyc.NotebookApp.notebook_dir #配置该参数 -
关联 conda 环境
- 方式一
Terminal window #在安装 jupyter notebook 的目录中执行conda install nb_conda #nb_conda 必须保证 python 版本小于 3.9(20230828), 建议使用 3.8 版本- 方式二(手动添加)
Terminal window activate des_dev #进入目标环境conda install ipykernel # #安装 ipykerneljupyter kernelspec list #查看 keneljupyter kernelspec remove kernel_name #删除 kernelpython -m ipykernel install --user --name <env_name> --display-name "<notebook_name>" #安装内核 -
管理 ipykernel 环境
jupyter kernelspec list #查看jupyter kernelspec remove kernel_name #删除2. Jupyterhub
Section titled “2. Jupyterhub”一个支持多用户管理的 jupyter 工具
- 安装
python3 -m pip install jupyterhubpython3 -m pip install jupyterpython3 -m pip install nb_conda_kernel #某些时候子环境中的 nb_conda 会不生效,在 jupyterhub 环境下安装该依赖进行尝试(具体的查看 jupyterhub 的运行日志)npm install -g configurable-http-proxy- 设置白名单
c.Authenticator.allowed_users = {'yangxy'}- 设置管理员
c.Authenticator.admin_users = {'yangxy'}c.Authenticator.allow_all = True #允许所有登录- ipython 脚本保持环境变量
c.Spawner.env_keep = ['JAVA_HOME','SPARK_HOME','PATH', 'PYTHONPATH', 'CONDA_ROOT', 'CONDA_DEFAULT_ENV', 'VIRTUAL_ENV', 'LANG', 'LC_ALL', 'JUPYTERHUB_SINGLEUSER_APP']- 设置不活跃自动关闭
pip install jupyterhub-idle-cullerc.JupyterHub.services = [ { 'name': 'cull-idle', 'admin': True, 'command': [ 'python3', '-m', 'jupyterhub_idle_culler', '--timeout=86400', # 超时时间,以秒为单位 '--cull-every=1800', # 每隔多少秒检查一次 '--concurrency=10', # 并发数量 '--cull-connected', #添加该选项则即使激活也会关闭,不添加该选择则会空间超时关闭 ], }]- 关联 conda 环境
conda create -n myenv ipython nb_conda3. Notebook
Section titled “3. Notebook”- shell 命令格式
!shell-
魔术命令
- 示例
% command #只针对单行有效%% commad #针对 cell 有效- 针对 google vertex AI 中的 Bigquery 魔法命令
%% bigqeury data #进行查询并且输出 data 的 dataframeselect ...