我想对我的IPython/IHaskell/Jupyter笔记本的外观进行一些简单的修改,比如
rendered_html :link {
text-decoration: none;
}
Run Code Online (Sandbox Code Playgroud)
但我无法弄清楚如何做到这一点.我已经尝试了许多通过搜索找到的解决方案,例如,将CSS放入其中
~/.ipython/profile_default/static/css/custom.css
Run Code Online (Sandbox Code Playgroud)
但没有任何影响,我怀疑,鉴于笔记本架构最近的变化,实现这一目标的方法已经改变,我发现的指令已经过时了.
如何为我的IPython/IHaskell/Jupyter Notebook设置自定义CSS?
OS X 10.10.4; Xcode 6.4; CLT:6.4.0.0.1; Clang:6.1; Python Python 2.7.10(Homebrew); IHaskell 0.6.4.1,IPython 3.0.0(4.0.0和Jupiter 4.0的答案也很受欢迎,因为我很快就会升级).
我运行这个:
In [303]: %prun my_function()
384707 function calls (378009 primitive calls) in 83.116 CPU seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
37706 41.693 0.001 41.693 0.001 {max}
20039 36.000 0.002 36.000 0.002 {min}
18835 1.848 0.000 2.208 0.000 helper.py:119(fftfreq)
Run Code Online (Sandbox Code Playgroud)
--snip--
每次tottime,percall,cumtime是什么?ncalls相当明显(调用函数的次数).我的猜测是,tottime是在函数中花费的总时间,不包括在其自己的函数调用中花费的时间; percall是???; cumtime是在函数调用中花费的总时间,包括在其自己的函数调用中花费的时间(当然,不包括重复计数).该文档是不是太有帮助; 谷歌搜索也没有帮助.
当我使用 VSCode 交互式 Python 时,有时会收到以下消息:
Output exceeds the size limit. Open the full output data in a text editor
它包含指向设置和文本编辑器的链接。然而,我常用的文本编辑器充满了未渲染的 unicode 符号,并且完全不可读(它应该显示错误的回溯)。
同时,这些设置不包含 Jupyter 的最大输出大小,这是在这篇文章中建议的:VS Code and Jupyter Notebook - how to open large output in text editor?
我该怎么做才能完整显示回溯?
更具体地说,是否有一个REPL具有(更多)丰富多彩的输出,漂亮的打印,标签完成以及ipython对node.js javascript/coffeescript的其他好处?
我怎样才能格式化IPython html显示的pandas数据帧呢
据我所知,numpy有设施set_printoptions,我可以这样做:
int_frmt:lambda x : '{:,}'.format(x)
np.set_printoptions(formatter={'int_kind':int_frmt})
Run Code Online (Sandbox Code Playgroud)
和其他数据类型类似.
但是,当在html中显示数据帧时,IPython不会选择这些格式选项.我还需要
pd.set_option('display.notebook_repr_html', True)
Run Code Online (Sandbox Code Playgroud)
但是如上所述的1,2,3.
编辑:下面是我对2和3的解决方案(不确定这是最好的方法),但我仍然需要弄清楚如何使数字列右对齐.
from IPython.display import HTML
int_frmt = lambda x: '{:,}'.format(x)
float_frmt = lambda x: '{:,.0f}'.format(x) if x > 1e3 else '{:,.2f}'.format(x)
frmt_map = {np.dtype('int64'):int_frmt, np.dtype('float64'):float_frmt}
frmt = {col:frmt_map[df.dtypes[col]] for col in df.columns if df.dtypes[col] in frmt_map.keys()}
HTML(df.to_html(formatters=frmt))
Run Code Online (Sandbox Code Playgroud) 我希望IPython笔记本代码单元的默认显示包含行号.
我从IPython/Jupyter笔记本中的显示行号中了解到,我可以使用ctrl-M L来切换它,这很棒,但手动.为了在默认情况下包含行号,我需要在ipython_notebook_config.py文件中添加一些内容.除非我遗漏了某些内容,否则在文档中没有解释如何执行此操作.
我最近更新了IPython(到4.0)并且在一段时间之后开始使用笔记本电脑不使用它们(因为在我之前的The Big Split之前),并且发现我的一些设置需要修改并从~/.ipython/到~/.jupyter/.
例如,它似乎NotebookManager.notebook_dir在
~/.ipython/profile_default/ipython_notebook_config.py
Run Code Online (Sandbox Code Playgroud)
被忽略,并将其功能替换为 FileContentsManager.root_dir in
~/.jupyter/jupyter_notebook_config.py
Run Code Online (Sandbox Code Playgroud)
但是,除了像这样的孤立事件之外,我还不清楚配置设置和配置文件现在如何工作.特别是哪些文件应该位于哪里,以及它们应该包含什么.例如,如果我生成一个新的配置文件
ipython profile create foo
Run Code Online (Sandbox Code Playgroud)
我现在获得的文件与以前不同(并且比我现有的配置文件中的文件要多):我以前在哪里获得
ipython_config
ipython_notebook_config.py
ipython_nbconvert_config.py
Run Code Online (Sandbox Code Playgroud)
我现在明白了
ipython_config.py
ipython_kernel_config.py
Run Code Online (Sandbox Code Playgroud)
并且尽可能地说,我ipython_notebook_config.py没有使用过.
这个(以及有限的文档)让我有点困惑我应该把我的设置和配置文件放在哪里用于IPython/Jupyter 4.0,具体来说:
~/.jupyter/jupyter_notebook_config.py,但我不清楚这些是否会覆盖从其他地方加载的设置.)ipython_notebook_config.py目录中的~/.ipython/profile_someprofile/文件吗?)ipython_kernel_config.py文件;我应该删除ipython_notebook_config.py和ipython_nbconvert_config.py文件吗?)OS X 10.10.4; Xcode 6.4; CLT:6.4.0.0.1; Clang:6.1; Python Python 2.7.10(Homebrew); Jupyter 4.0.4; IPython 4.0.0.
为了简化Ipython的调试,我在脚本的开头添加了以下内容
from IPython.Debugger import Tracer
debug = Tracer()
Run Code Online (Sandbox Code Playgroud)
但是,如果我从命令行启动我的脚本
$ python myscript.py
Run Code Online (Sandbox Code Playgroud)
我收到了与Ipython相关的错误.有没有办法做到以下几点
if run_from_ipython():
from IPython.Debugger import Tracer
debug = Tracer()
Run Code Online (Sandbox Code Playgroud)
这样我只需要在需要时导入Tracer()函数.
在使用IPython笔记本电脑时,我越来越发现自己希望笔记本电脑附带一个控制台,用于交互式编程.我发现自己添加行来测试代码片段然后删除它们,这是很好的用法.在更糟糕的用法中,我正在改变同一行中的命令,一遍又一遍地评估行,完全改变行的目的,直到我做对了,然后我一直Ctrl-Z回到原始单元格内容.
如果我可以在笔记本底部安装一个交互式翻译,那肯定会提高我的工作效率.我知道笔记本有一个内核,但我无法附加一个新的ipython控制台.所以我的奇迹是:
谢谢!
我无法确定ipython存储历史的位置.
一个.没有〜/ .pythonhistory:
12:49:00/dashboards $ll ~/.py*
ls: /Users/steve/.py*: No such file or directory
Run Code Online (Sandbox Code Playgroud)
湾 python启动文件中没什么特别之处:
12:49:07/dashboards $echo $PYTHONSTARTUP
/shared/.pythonstartup
12:49:43/dashboards $cat /shared/.pythonstartup
import rlcompleter
import readline
readline.parse_and_bind("tab: complete")
Run Code Online (Sandbox Code Playgroud)
C.但是:当我启动ipython时,我确实有很多历史可用.
那么历史存储在哪里?
更新 @Stefano的答案导致了正确的方法:这是实际路径
13:30:05/shared $ll ~/.ipython/profile_default/history.sqlite
-rw-r--r-- 1 steve staff 372736 Jun 3 12:48 /Users/steve/.ipython/profile_default/history.sqlite
Run Code Online (Sandbox Code Playgroud) ipython ×10
python ×5
jupyter ×3
coffeescript ×1
html ×1
ihaskell ×1
interpreter ×1
javascript ×1
node.js ×1
pandas ×1
profiler ×1
settings ×1