Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

running win32 ipython binaries interactively from cygwin

Tags:

python

cygwin

I would really like to run my Win7 ipython interactively inside a proper terminal and shell provided by cygwin (mintty or rxvt would be great).

I have had some success with python, but IPython is not really cooperating. If we run this from rxvt bash prompt:

$ /cygdrive/c/pydir/python.exe -i

I end up with a fairly successful python interactive session. But vanilla python is just not as wonderful as IPython. So then I try this:

$ /cygdrive/c/pydir/ipython.exe

and the program just blocks the bash prompt, and seems to spawn an entirely separate process (which does not produce any windows, or show signs of stdin/stdout).

If instead I use this:

$ /cygdrive/c/pydir/python.exe -i /cygdrive/c/pydir/ipython-script.py

it is exciting at first, but you quickly realize that ipython is not properly engaging with the terminal. There is no readline support, poor cursor control, stdin seems to handle typical python, but there are no [out] prompts (although "prints" do spit out text), simple things like backspace/enter/tab seem completely broken (the cursor is very defiant), there is nothing like an ncurse buffer being maintained (you can just type over the ipy command prompts). Once I have given up on the session, exiting becomes another problem. I can return to the bash prompt, but I have no standard input. It turns out that there is always a python.exe process hanging that must be killed from the Windows side (and it doesnt release stdin until it dies).

Is there a quick fix or alternate method to run Ipython in this manner? I can do most of my development using the cygwin binaries, but being able to run win32 binaries interactive would help tremendously when debugging/testing win32 specific python libraries.


P.S.:::: I really need tab-completion and clean output. I am trying to piece my way through a bunch of COM interfaces, and the only way I can get anywhere is with an interactive ipy session.

P.S.:::: I am using a 64-bit Cygwin and a 32-bit win32 python. Could this be simple mismatch?

like image 410
user2097818 Avatar asked Oct 22 '22 05:10

user2097818


1 Answers

Running win32 IPython.exe executables in cygwin is problematic at best. Best to run the cygwin Ipython version. Depending on the libraries you need, this can work just fine. But if you need to work with win32 compiled libraries, the cygwin Ipython will not work (as far as I know).

Overall, I still struggle for pleasant terminal experiences with ipython in Windows. There is no one solution that "just works". I have 3 different ways of interacting with IPython, depending on the job I need to get done.

  1. Use cmd.exe (or Console.exe) and run the win32 ipython. This is the best way (in my opinion) for a vim+ipython workflow. This is very functional and fast. It will hurt your eyes a little, and still lacks a good "terminal" experience... but it will get the job done if you need to grind through some work. Extra Bonus: Seems like a few extra ipy %magics work better in this workflow.

  2. Use cygwin and the ipython package that comes with cygwin. You lose "native" win32 support, but if you generally only need the standard library, this will look better and feel better (assuming you go all the way with CygwinX and run your favorite terminal).

  3. Use win32 Ipython, and get QTConsole working. If your in Windows and you haven't already tried QTConsole, go get it right now and spend a little time setting it up. It can be extremely fast and pleasant (fonts that don't hurt my eyes!), and its loaded with features. Its biggest drawbacks: it doesn't handle some %magics well (like %edit, so I lose my vim+ipython workflow),it doesn't do system background processes well, and it won't always handle stdin/stdout like you would think. But, if you combine QTConsole with the cmd.exe ipython, and give it a little practice+patience, you can get a pretty decent "console" development workflow.

like image 56
user2097818 Avatar answered Nov 03 '22 19:11

user2097818