how to launch recent Jupyter QtConsole on Windows without a console window
Asked Answered
R

1

9

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

Rhoads answered 12/9, 2018 at 14:29 Comment(3)
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.Leaves
Which versions are you using? I don't see the problem with Py2.7 win64 + qtconsole 4.4.1Sextan
@Sextan Python 3.6 and Python 3.7 using Anaconda DistributionRhoads
S
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.

Sextan answered 12/9, 2018 at 17:14 Comment(15)
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 workRhoads
@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 <name>-script.py -- that seems to have changed now.Sextan
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.exeRhoads
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 worksRhoads
@VinceW. This seems to be fixed in the recent version of qtconsole. Gimme a sec to pinpoint the commit/PR.Sextan
@VinceW. Okay, that should do it.Sextan
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.Rhoads
@VinceW. I think you'll be able to award a bounty in a day or so :)Sextan
@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.Sextan
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 whateverRhoads
@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).Sextan
@VinceW. Actually, here: #46306069Sextan
I have filed a bug as requested: github.com/conda-forge/qtconsole-feedstock/issues/15Microclimatology
@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!Rhoads
@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.Sextan

© 2022 - 2024 — McMap. All rights reserved.