8

This older question appears to be out of date.

It used to be (based on reading git repos and the qtconsole issue tracker) you could launch the Jupyter QtConsole without a console window running the background with:

pythonw -m jupyter qtconsole

However, in recent versions of Jupyter, this still launches the background console window.

enter image description here

I am wondering if anyone knows how to launch the QtConsole without the annoying console window. I know you can do this from the Anaconda Navigator program, but I don't want to launch one program so that I can then launch another program. I would prefer to have a simple batch script or even a python script so that I can launch with a Start Menu shortcut

Running the module directly also does not work:

pythonw -c "from qtconsole.qtconsoleapp import main; main()"

This still launches a new console window as in the picture, so I don't really know if this is possible in some straightforward way, or if the Anaconda Navigator is doing some black magic to make this happen

ivan_pozdeev
  • 28,628
  • 13
  • 85
  • 130
Vince W.
  • 2,888
  • 1
  • 17
  • 51
  • It seems that "C:\Miniconda3\Scripts\jupyter-qtconsole.exe" is a console application, which automatically allocates a console if it doesn't inherit one, which obviously it won't inherit from pythonw.exe. Look for a non-console version in that directory. If there isn't one, you're going to need an adapter script that runs this command with a hidden or windowless console. – Eryk Sun Sep 12 '18 at 17:01
  • Which versions are you using? I don't see the problem with Py2.7 win64 + qtconsole 4.4.1 – ivan_pozdeev Sep 12 '18 at 18:03
  • 1
    @ivan_pozdeev Python 3.6 and Python 3.7 using Anaconda Distribution – Vince W. Sep 12 '18 at 18:05

1 Answers1

5

There are two problems here:

Both of these are specific to Anaconda and do not happen with the stock Python. As such, file a bug against https://github.com/conda-forge/qtconsole-feedstock to get this fixed.

These are the workarounds:

  • For the first bug, run pythonw <Scripts_dir>\jupyter-qtconsole-script.py which is the script that the .exe wraps.
    (This is Anaconda-specific. Regular Python uses a different wrapping mechanism. Anaconda must be patching setuptools or something.)
  • For the second one, replace the full path in the aforementioned kernel.json with "python". This change will be overwritten when you update the ipykernel package that this file belongs to (this can be checked by searching for it in %CONDA_PREFIX%\pkgs).

The OP reports that this solution may break other Anaconda packages. I believe those that break make assumptions about the availability of standard streams. Though it too counts as a bug in my book, it must be coming from the fact that Anaconda packages aren't tested with this setup.


To create a shortcut/batch file to run the above command in Anaconda Prompt environment, see e.g. How to make batch files run in anaconda prompt.

ivan_pozdeev
  • 28,628
  • 13
  • 85
  • 130
  • 1
    the information in that page is either specific to something about their custom winpython environment, or is just flat out of date. Using a current Anaconda environment, this does not work – Vince W. Sep 12 '18 at 17:47
  • @VinceW. the idea here is to directly run the script that `Scripts\jupyter-qtconsole.exe` wraps. I remember that previously, it was indeed available as `-script.py` -- that seems to have changed now. – ivan_pozdeev Sep 12 '18 at 17:54
  • if you have a working example, I would love to see it. I have tried all variants that I know. the jupyter-script.py simply imports main from qtconsole.qtconsoleapp and then runs main(). This process itself generates a new command window if run from pythonw.exe – Vince W. Sep 12 '18 at 17:56
  • so for example `pythonw -c "from qtconsole.qtconsoleapp import main; main()"` will launch a new cmd window that it uses to run the ipykernel. I suppose its possible there is no good way around this, but people do find ways, I just don't know how it works – Vince W. Sep 12 '18 at 17:59
  • @VinceW. This seems to be fixed in the recent version of `qtconsole`. Gimme a sec to pinpoint the commit/PR. – ivan_pozdeev Sep 12 '18 at 18:04
  • @VinceW. Okay, that should do it. – ivan_pozdeev Sep 13 '18 at 20:43
  • thanks, now how can I upvote this more than once? I added some further instructions in your answer that are again Anaconda specific in order to launch the QtConsole from the start menu. – Vince W. Sep 13 '18 at 21:06
  • 1
    @VinceW. I think you'll be able to award a bounty in a day or so :) – ivan_pozdeev Sep 13 '18 at 21:14
  • @VinceW. your suggested edit will likely be rejected as an "attempt to reply" because it clearly deviates from the question as asked (creating a batch file to run something in the same environment as Anaconda Console is a completely different concern). You may post your own answer with those details though. – ivan_pozdeev Sep 13 '18 at 21:19
  • Okay, will do that if the edit is rejected unless you want to add it as an appendix yourself. Seems unnecessary to have two answers but whatever – Vince W. Sep 13 '18 at 21:21
  • @VinceW. SO's principle is one-concern-per-question. So it's better fit for another question which can be referenced here instead (in particular, because I'm sure there are more robust/manageable ways to do that). – ivan_pozdeev Sep 13 '18 at 21:26
  • 1
    @VinceW. Actually, here: https://stackoverflow.com/questions/46305569/how-to-make-batch-files-run-in-anaconda-prompt – ivan_pozdeev Sep 13 '18 at 21:26
  • 1
    I have filed a bug as requested: https://github.com/conda-forge/qtconsole-feedstock/issues/15 – Filip S. Sep 17 '18 at 09:54
  • 1
    @ivan_pozdeev, don't know if its worth putting in the answer, but I have since figured out that this can break other apps. JupyterLab for instance goes into an infinite kernel restarting loop. YAY! – Vince W. Sep 19 '18 at 18:24
  • @VinceW. yes, this is worth putting into the answer: it's a drawback of the solution that one needs to be informed of when considering using it. – ivan_pozdeev Sep 19 '18 at 18:55