7

I have ipython with qtconsole installed and can start it via ipython qtconsole. I can also run a script via ipython -i my_script.py to stay in the interactive interpreter after the script finishes or if an exception is thrown. But I could not figure out how to combine them: I would like to do ipython -i qtconsole my_script.py but whatever I try, it complains about invalid flags. Any hint how to do that?

philshem
  • 22,161
  • 5
  • 54
  • 110
Achim
  • 14,333
  • 13
  • 70
  • 128

1 Answers1

6

Interesting, it seems that either this option was forgotten or not wanted in the qtconsole. A way around this (or perhaps an intended way?) is to use the -m flag. This runs a module as a script so you if you called:

ipython qtconsole -m my_script

it will run the code in my_script, for me this works. Notice it needs to be my_script not my_script.py otherwise it will throw an error since it's looking for the module not the file. Hope that helps.

LeoRochael
  • 10,305
  • 5
  • 23
  • 32
Greg
  • 9,973
  • 1
  • 40
  • 47
  • Works for me with and without ending, but gives a unknown failure at the end in case of using the ending – embert Jan 28 '14 at 09:18
  • 1
    This is because the `-m` flag is looking for a module. So it looks in the current directory for a file named `my_scipy.py`, if you call it with `-m my_script.py` then it will look for `my_script.py.py`. More information on import modules and writing your own can be found [here](http://docs.python.org/2/tutorial/modules.html). – Greg Jan 28 '14 at 09:27
  • How to run qtconsole from source code? In other words: what is source code of `%qtconsole` magic? – Jo Ja Feb 27 '21 at 10:19