当前位置: 首页 > news >正文

【Jupyter】个人开发常见命令

1. 查看python版本

import sys
print(sys.version)

2. ipynb/py文件转换

	jupyter nbconvert --to python my_file.ipynbipynb转换为mdjupyter nbconvert --to md my_file.ipynbipynb转为htmljupyter nbconvert --to html my_file.ipynbipython转换为pdfjupyter nbconvert --to pdf my_file.ipynb

	py --> ipynbIn [ ]:%run file.py加载了file.py文件,相当于导包。In [ ]:%load file.py把flie.py的代码显示出来

3. magic 函数

%! [cmd]
%time
%matplotlib inline
%history
%load file.py

4. plotly

jupyter notebook可以直接在里边画图,并以html显示出来。
import plotly.offline as py
py.init_notebook_mode(connected=True)

!但是jupyter lab不可以,需要安装其他的插件。

5. tqdm

解决tqdm不能显示的问题:

#usual installation 
pip install ipywidgets 
jupyter nbextension enable --py widgetsnbextension
#you are my saver!
jupyter labextension install @jupyter-widgets/jupyterlab-manager

6. 展示所有行所有列

import pandas as pd
pd.set_option('display.width', 500)    #设置整体宽度
pd.set_option('display.height', 500)    #设置整体高度
pd.set_option('display.max_rows',100)   #设置最大行数
pd.set_option('display.max_columns', 100) #设置最大列数#显示所有列
pd.set_option('display.max_columns', None)
#显示所有行
pd.set_option('display.max_rows', None)# 以下可能存在问题
pd.set_option('max_columns',100)
pd.set_option('max_row',100)

7. 单cell多变量输出

from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"

8. 刷新(清除)动画输出

# 每一帧会刷新
from IPython.display import display, clear_output
clear_output(wait=True)

9. 疑难问题

多进程

问题:Pycharm可以跑,但需要在jupyter上运行,出现的问题是:程序一直在运行中,但是没有输出结果。

1.jupyter notebook/lab中直接使用多进程的话,虽然在界面上不会报错,但一直会处于运行状态,去查看命令行的话会看到报错:
AttributeError: Can’t get attribute ‘XXX’ on <module ‘main’ >,由于某些原因Pool不能始终使用未在导入的模块中定义的对象。

2.jupyter只能跟踪主进程,没法跟踪子进程? (如何理解)

方法一:
将代码打包成py文件,再让jupyter,导入函数执行。

方法二:
在jupyter里,使用magic函数 %%writefile,并且运行。

调整jupyter 内存大小
$cd .jupyter/$ls
jupyter_lab_config.py       lab       nbconfig
jupyter_notebook_config.py  migrated  serverconfig
  1. 打开Jupyter Notebook并选择New -> Terminal。
  2. 在终端中输入以下命令:jupyter notebook --generate-config,它将生成一个配置文件jupyter_notebook_config.py。
  3. 打开配置文件,找到以下代码并取消注释: #c.NotebookApp.max_buffer_size = 100000000 并将数字“100000000”更改为您想要的内存大小。
  4. 保存并关闭配置文件。
  5. 重新启动Jupyter Notebook,并您的内存大小就已经更改了。
http://www.dtcms.com/a/282799.html

相关文章:

  • 多房间 WebSocket 连接管理设计:从单例模式到多终端连接池
  • 【Unity】IL2CPP相关理论知识学习
  • Transformer 架构
  • 多语言json文件内\n换行不生效问题
  • ScratchCard刮刮卡交互元素的实现
  • 列车调度(vector)
  • 前端vue3获取excel二进制流在页面展示
  • 【unity知识点】已知发射的初始位置和目标位置,计算发射初速度,实现投掷物品或者弓箭手做抛体线运动精准的击中目标
  • C语言 --- 函数递归
  • Python编程基础(六)| 用户输入和while循环
  • 康华生物:以创新疫苗书写国产突围之路​​​
  • 李宏毅2025《机器学习》第七讲-推理模型:从原理、流派到未来挑战
  • 2025年自动化工程、物联网与计算机应用国际会议(AEITCA 2025)
  • 【时序数据库-iotdb】时序数据库iotdb的可视化客户端安装部署--dbeaver
  • 基于Spring AI Alibaba的智能知识助手系统:从零到一的RAG实战开发
  • 最细,Web自动化测试入门到精通整理,一套打通自动化测试...
  • ASP .NET Core 8集成Swagger全攻略
  • 从零开发足球比分APP:REST API与WebSocket的完美搭配
  • HAProxy简介及配置文件详解
  • ESP‑IDF 默认的连接流程是
  • 2_概要设计编写提示词_AI编程专用简化版
  • 快速开发汽车充电桩的屏幕驱动与语音提示方案
  • __is_constexpr(x)宏介绍---max()宏扩展
  • Linux 常用指令
  • 信而泰×DeepSeek:AI推理引擎驱动网络智能诊断迈向 “自愈”时代
  • Java基础语法补充v2
  • C# --- 单例类错误初始化 + 没有释放资源导致线程泄漏
  • The 2024 ICPC Asia Shenyang Regional Contest B. Magical Palette
  • Docker容器技术讲解
  • Liunx练习项目6-创建dns服务器