当前位置: 首页 > 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.lryc.cn/news/590576.html

相关文章:

  • HugeGraph 【图数据库】JAVA调用SDK
  • ByteToMessageDecoder详解
  • Spring AI快速入门
  • VisualVM监控远程Linux的java进程
  • 【SpringBoot】实战-开发接口-用户-注册
  • matlab的伯德图为何从360度显示?应如何修改解决?
  • 基于大数据的网络文学推荐分析系统的设计与实现【海量书籍、自动爬虫】
  • Redis1:高并发与微服务中的键值存储利器
  • mongodb操作巨鹿
  • DHTMLX Suite 9.2 重磅发布:支持历史记录、类Excel交互、剪贴板、拖放增强等多项升级
  • Qt小组件 - 6 异步运行函数
  • Redis深度解析:从缓存到分布式系统的核心引擎
  • Java高并发编程(2)
  • beautiful-react-hooks库——入门实践常用hook详解
  • React之旅-09 useMemo,优化计算性能的利器
  • React 源码7:Lane、React和schedule优先级转换
  • WPF 多窗口分文件实现方案
  • 【MAC】nacos 2.5.1容器docker安装
  • QT——事件系统详解
  • 多语言json文件内\n换行不生效问题
  • React -自定义hooks - 封装双向数据绑定
  • React 中 props 的最常用用法精选+useContext
  • H3CNE综合实验之机器人
  • Antd中使用Table集成 react-resizable实现可伸缩列
  • PowerJob集群机器数为0问题
  • 深度剖析 TDMQ RabbitMQ 版经典队列底层存储机制
  • vue页面不销毁的情况下再返回,总是执行created,而不触发 activated
  • QOpenGLWidget自定义控件— 2D点云显示(支持平移、放缩、绘制网格)
  • SpringBoot集成Minio存储文件,开发图片上传等接口
  • 【c++深入系列】:万字详解list(附模拟实现的list源码)