ipython

在Jupyter Notebook中增加Python内核

北城以北 提交于 2019-12-17 21:35:26
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 本人在Python 3.6的环境下,安装了Jupyter pip3 install jupyter 进入到Jupyter Notebook后,点击Kernel菜单的Change kernel子菜单,只看到只有一个Python 3。如果这时想要增加Python 2的内核(Python 2.7),可通过以下方式操作 安装 ipykernel pip install ipykernel 在安装时,出现了报错 Complete output from command python setup.py egg_info: IPython 6.0+ does not support Python 2.6, 2.7, 3.0, 3.1, or 3.2. When using Python 2.7, please install IPython 5.x LTS Long Term Support version. Beginning with IPython 6.0, Python 3.3 and above is required. 也就是说最新版的 IPython 不支持 Python 2.7,这时可先单独安装ipython,并指定旧的版本号进行安装 pip install ipython==5.3.0 如果版本不存在的

Why is the order of dict and dict.items() different?

浪子不回头ぞ 提交于 2019-12-17 20:54:07
问题 >>> d = {'A':1, 'b':2, 'c':3, 'D':4} >>> d {'A': 1, 'D': 4, 'b': 2, 'c': 3} >>> d.items() [('A', 1), ('c', 3), ('b', 2), ('D', 4)] Does the order get randomized twice when I call d.items()? Or does it just get randomized differently? Is there any alternate way to make d.items() return the same order as d? Edit: Seems to be an IPython thing where it auto sorts the dict. Normally dict and dict.items() should be in the same order. 回答1: You seem to have tested this on IPython. IPython uses its

When I am in the Python or IPython console, what is called when I am returned an output?

折月煮酒 提交于 2019-12-17 20:48:01
问题 For example, python >> x = 1 >> x 1 I'm curious about what method/function on x is returning 1. I'm asking because I'm seeing differences between calling print x and simply x . Similary, is there a way to specify what is called? Does this configuration exist in IPython? 回答1: When you inspect an object in that manner in a REPL, it invokes the object's __repr__ method. In comparison, print uses the object's __str__ method. Example: >>> class Widget: ... def __repr__(self): ... return "repr of a

PyDev: How to invoke debugging specific command from console (with breakpoints)?

让人想犯罪 __ 提交于 2019-12-17 19:45:56
问题 Suppose I wrote a function, which I want to debug. PyDev helps debugging a lot with its advanced features, like breakpoints. After setting the breakpoints, one way of debugging is to write an invocation of the function in def main() or just in the body of the module, and to press the button. Is it possible to launch a debug session of the function together with its arguments from the console? (Just like in RStudio or VBA...) This question is a duplicate of pydev: debug in console mode

How to have win32com code completion in IPython?

二次信任 提交于 2019-12-17 19:25:44
问题 Via import win32com.client wordapp = win32com.client.gencache.EnsureDispatch('Word.Application') I can get a Word Application object documented e.g. here. However, ipython 's autocompletion is not aware of that API, is there any way to add that? 回答1: Quick solution Perhaps the simplest way to achieve code completion in IPython (tested with 6.2.1) and Jupyter is to run the following snippet: from IPython.utils.generics import complete_object import win32com.client @complete_object.when_type

Simple way to choose which cells to run in ipython notebook during run all

▼魔方 西西 提交于 2019-12-17 18:24:48
问题 I have an ipython notebook that runs several steps in a data processing routine and saves information in files along the way. This way, while developing my code (mostly in a separate .py module), I can skip to and run various steps. I'd like to set it up so that I can Cell -> run all but only have it execute certain chosen steps that would be easily chosen. e.g., I'd envision defining the steps I want to run in a dict like so: process = { 'load files':False, 'generate interactions list':False

How can I do an “if run from ipython” test in Python?

隐身守侯 提交于 2019-12-17 17:55:10
问题 To ease debugging from Ipython, I include the following in the beginning of my scripts from IPython.Debugger import Tracer debug = Tracer() However, if I launch my script from the command line with $ python myscript.py I get an error related to Ipython. Is there a way to do the following if run_from_ipython(): from IPython.Debugger import Tracer debug = Tracer() This way I only import the Tracer() function when I need it. 回答1: This is probably the kind of thing you are looking for: def run

How to use pipe in IPython

╄→гoц情女王★ 提交于 2019-12-17 16:09:48
问题 In a Linux terminal, when the output of one command is too long to read in one page, I can do this: cat file | less so that I can read and scroll up and down the output from the cat file. How can I do this in IPython? For example, I tried this and it didn't work: whos | less My original problem is that the output from whos is too much to be seen by doing Shift+Page Up and I don't want to change the scroll buffer. 回答1: In IPython, you can use %page obj to show the object obj using your

ipython notebook clear cell output in code

你。 提交于 2019-12-17 15:10:23
问题 In a iPython notebook, I have a while loop that listens to a Serial port and print the received data in real time. What I want to achieve to only show the latest received data (i.e only one line showing the most recent data. no scrolling in the cell output area) What I need(i think) is to clear the old cell output when I receives new data, and then prints the new data. I am wondering how can I clear old data programmatically ? 回答1: You can use IPython.display.clear_output to clear the output

convert json ipython notebook(.ipynb) to .py file

若如初见. 提交于 2019-12-17 10:25:41
问题 How do you convert an IPython notebook file (json with .ipynb extension) into a regular .py module? 回答1: From the notebook menu you can save the file directly as a python script. Go to the 'File' option of the menu, then select 'Download as' and there you would see a 'Python (.py)' option. Another option would be to use nbconvert from the command line: jupyter nbconvert --to script 'my-notebook.ipynb' Have a look here. 回答2: According to https://ipython.org/ipython-doc/3/notebook/nbconvert