If in the pydev 2.5 with Ipython console 0.11 I write:
import numpy
numpy?
I get the documentation for numpy and as it's longer than the screen it gets paged showing the message:
---Return to continue, q to quit---
However no matter what keys I press it'll stay there. typically I'll have to restart the console to continue.
Is this a bug?
It seems that the console is not sending the key press to actually perform the paging.
A workaround is to redefine the ipython paging function to never actually page.
Add the following code to the 'Initial interpreter commands' (PyDev -> Interactive Console)
from IPython.core import page
def nopage(strng, start=0, screen_lines=0, pager_cmd=None):
print(strng)
page.page = nopage
Related
For reasons outside of my control I'm stuck using python 2.6.6 and IPython 0.10.2. I also normally use the tcsh shell, and have gotten quite used to completing a command from the history using <A-p> (i.e. pressing the ALT key and p). However, this doesn't work in IPython. I know I can press <C-r> and then start typing a command, but what inevitably is happening is that I start a command, press <A-p>, get a colon indicating some weird state, then exit out of that state, delete my command, press <C-r> then search for my command. It's getting rather irritating. Is there any way to make <A-p> complete my already started command by relying on the history?
Ouch, this is an old version of IPython, Python (and pip). The bad news is I don't have much experience with such an old version of IPython, the good new is; it was way simpler at that time.
Most of the shortcut and feature are provided using readline, and the python bindings of stdlib. Meaning that most likely what you are trying to configure is readline itself and not only IPython; so you can find more information on that outside of IPython !
The secret is to grep in the source-code for parse_and_bind, then you'll find the following example configuration, leading me to change the ~/.ipython/ipy_user_conf.py to be like so at around line 99 (all indented an extra 4 space to be in the main() function):
import readline
readline.parse_and_bind('set completion-query-items 1000')
readline.parse_and_bind('set page-completions no')
rlopts = """\
tab: complete
"\C-l": possible-completions
set show-all-if-ambiguous on
"\C-o": tab-insert
"\M-i": " "
"\M-o": "\d\d\d\d"
"\M-I": "\d\d\d\d"
"\C-r": reverse-search-history
"\C-s": forward-search-history
"\C-p": history-search-backward
"\C-n": history-search-forward
"\e[A": history-search-backward
"\e[B": history-search-forward
"\C-k": kill-line
"\C-u": unix-line-discard"""
for cmd in rlopts.split('\n'):
readline.parse_and_bind(cmd)
The repetition of commands make me think that what \C,\M or [e mean might be system dependant. I would bet on \C being Control, and \M being Meta (Alt, Opt), but at least one of these line did the trick for me (and also now tab allows to complete). See also man readline for the list of commands you can bind to what, and enjoy! Hoping you can upgrade to Python 3 and IPython 6 at some point.
[Edit]
See Eric Carlsen second comment under this answer for how it was resolved.
Typing
import pyqtgraph as pg
pg.plot([1,2,3,2,3])
into the standard Python REPL opens a window containing a plot of the data. Typing exactly the same code into the IPython REPL or the Jupyter console, opens no such window.
[The window can be made to appear by typing pg.QtGui.QApplication.exec_(), but then the REPL is blocked.
Alternatively, the window appears when an attempt is made to exit the REPL, and confirmation is being required.
Both of these are highly unsatisfactory.]
How can basic interactive pyqtgraph plotting be made to work with the IPython REPL?
[The described behaviour was observed in IPython 5.1.0 and Jupyter 5.0.0 with Python 3.5 and 3.6 and PyQt4 and PyQt5 (no PySide)]
As sugested by #titusjan, the solution is to type
%gui qt
(or some variation on that theme: see what other options are available with %gui?) in IPython before issuing any pyqtgraph (or PyQt in general) commands.
I had a problem with matplotlib in Jupyter Notebook. It was not fast enough and I found the navigation to be deficient. I got pyqtgraph to work using tips I found here. OMG! This is a great tool. The navigation and the speed you get is awesome.
Thought I would share my solution here.
%gui qt5
from PyQt5.Qt import QApplication
# start qt event loop
_instance = QApplication.instance()
if not _instance:
_instance = QApplication([])
app = _instance
import pyqtgraph as pg
# create and and set layout
view = pg.GraphicsView()
view.setWindowTitle('Your title')
layout = pg.GraphicsLayout()
view.setCentralItem(layout)
view.show()
# Set white graph
pg.setConfigOptions(antialias=True)
pg.setConfigOption('background', 'w')
pg.setConfigOption('foreground', 'k')
# add subplots
p0 = layout.addPlot(0,0)
p0.addLegend()
p0.plot([1,2,3,4,5], pen='b', name='p0')
p1 = layout.addPlot(1,0)
p1.addLegend()
p1.plot([2,2,2,2,], pen='r', name='p1')
p2 = layout.addPlot(1,0)
p2.addLegend(offset=(50, 0))
p2.plot([-1,0,1,1,], pen='g', name='p1.1')
p2.hideAxis('left')
p2.showAxis('right')
You will get a pop up window like that
I'm running some data analysis in ipython notebook. A separate machine collects some data and saves them to a server folder, and my notebook scans this server periodically for new files, and analyzes them.
I do this in a while loop that checks every second for new files. Currently I have set it up to terminate when some number of new files are analyzed. However, I want to instead terminate upon a keypress.
I have tried try-catching a keyboard interrupt, as suggested here: How to kill a while loop with a keystroke?
but it doesn't seem to work with ipython notebook (I am using Windows).
Using openCV's keywait does work for me, but I was wondering if there are alternative methods without having to import opencv.
I have also tried implementing a button widget that interrupts the loop, as such:
from ipywidgets import widgets
import time
%pylab inline
button = widgets.Button(description='Press to stop')
display(button)
class Mode():
def __init__(self):
self.value='running'
mode=Mode()
def on_button_clicked(b):
mode.value='stopped'
button.on_click(on_button_clicked)
while True:
time.sleep(1)
if mode.value=='stopped':
break
But I see that the loop basically ignores the button presses.
You can trigger a KeyboardInterrupt in a Notebook via the menu "Kernel --> Interrupt".
So use this:
try:
while True:
do_something()
except KeyboardInterrupt:
pass
as suggested here and click this menu entry.
I'm using large dataframe from Pandas in the interactive IPython console in Pydev/Eclipse. Every time I try to access dataframe attributes or methods, the console freeze for a few seconds after I type df.. Apparently it looks for completitions and maybe accidently calls some lengthy operation in the background.
Is there a way to avoid that?
You can control much of the behaviour by setting Eclipse Preferences. You can start to disable all and try re-enable things you need.
PyDev->Editor->Code Analysis
PyDev->Editor->Code Completion
What could be your problem
Request completion on '.'
Other Strategies
Disable Code Analysis within special modules by using a special
comments in source.
Disable Automatic Code Analysis and trigger it with a shortcut (show all pydev shortcut with SHIFT+CTRL+L)
I'm running Matlab 2013a, under Linux, using Xmonad (using the XMonad.Config.Xfce package).
This problem occurs whether the command window is docked or not.
The command window prompt does not get the keyboard focus unless the pointer is located
over the command window.
Is there a way to get the Matlab command window to have focus behaviour just like other normal windows, like a terminal?
Most important: I'd like to have the keyboard focus follow the window focus,
and not require any special positioning of the pointer, so that I can just "Alt-Tab" around my windows and have the command window get the keyboard focus. All of the resources I've found so far relate to programmatic control of focus; I'm just trying to improve my user experience in an interactive session.
To get keyboard focus on the Command Window, include the following in your xmonad.hs
import XMonad.Hooks.SetWMName
import XMonad.Hooks.ManageHelpers
and configure your ManageHook as follows
myManageHook = composeAll . concat $
[ [appName =? a --> doCenterFloat | a <- myFloatAS ]
, (your other hooks)
] where
myFloatAS = ["MATLAB"]
Finally, include setWMName "LG3D" in your startupHook. See here for a full xmonad.hs configuration which uses this (this is where I found the solution). If you have other Java apps that don't get focus as they should you can add them to the myFloatAS list.
It's a problem in the built-in java.
If i run:
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre
matlab -desktop
Matlab works as expected.
I ran into this problem, running MATLAB2014a. I set up setWMName "LG3D" but still i couldn't get focus on my window. I had to click on the focused window to get the cursor, and sometimes the situation was even worse and I had to click on random places till i get my cursor back. This wouldn't happen on MATLAB2010. What worked for me was to use the native version of java as describe above.
In the end, i used the following bash script to start matlab8:
#!/bin/bash
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk-amd64/jre/
/usr/local/bin/matlab8 -desktop -nosplash