takluyver / nbopen

Open a Jupyter notebook in the best available server
BSD 3-Clause "New" or "Revised" License
301 stars 58 forks source link

python.exe window won't close on windows 10 #54

Open richardwmcgovern opened 6 years ago

richardwmcgovern commented 6 years ago

I followed the instructions to integrate with my file manager on Windows 10 by running:

python3 -m nbopen.install_win

It works and I am able to double-click open .ipynb files in a jupyter notebook. Doing so opens a python.exe blank terminal window (running it I presume). Unfortunately this window never closes, even after I close and halt the notebook, close the browser tabs, CNTRL + C in the anaconda prompt, close my browser. I have to restart my whole system to close those pesky python windows.

takluyver commented 6 years ago

I wonder, if your exe is called python3.exe instead of python.exe, this check might not be working:

https://github.com/takluyver/nbopen/blob/332b955e8393f1e1d7da7ad306120b2de16138ad/nbopen/install_win.py#L18-L20

Can you find the registry key it's set and check what Python exe it points to?

richardwmcgovern commented 6 years ago

I'm not really sure how. Poking around regedit right now. Do you want to know the registry key for my nbopen? I don't see it in here: HKEY_CURRENT_USER\Software\Python\PythonCore\3.5\InstalledFeatures

All of the python executables in Anaconda and elsewhere when I see them in File Explorer read "python.exe." Could it be because I use an environment named "python3" ?

takluyver commented 6 years ago

Have a look for HKEY_CURRENT_USER\Software\Classes\Jupyter.nbopen\shell\open\command

richardwmcgovern commented 6 years ago

I have one entry there. Here is what I get for the value string: "C:\Users\\Anaconda3\pythonw.exe" -m nbopen "%1"

takluyver commented 6 years ago

OK, so it did get pythonw correctly. Usually the w means that it shouldn't bring up the console window - I don't know why that's not working for you.

richardwmcgovern commented 6 years ago

In case it matters, the extra python window does not pop up if I first open it normally through anaconda command prompt:

> jupyter notebook "mynotebook.ipynb"

Then close the browser tab. Then double-click the .ipynb file to re-open (does not open a python window). The anaconda command prompt remains open this entire time. But I can close it manually with no problem. Not sure what's causing it to open and stay open otherwise.

takluyver commented 6 years ago

Ah, I bet that the cmd window opens for the kernel.

Nbopen does two different things, depending on whether Jupyter is already running. If Jupyter is running and can access the notebook, Nbopen just opens a new tab on your existing server. If not, it launches a new Jupyter server to show you the notebook you want.

When your server is running in a command prompt, the kernels it starts will inherit that console window automatically. But when it's running without a command prompt, because it was launched by double clicking a file, a new console is created for the kernel.

If I'm right, you can probably fix this locally by editing a kernel.json file (use jupyter kernelspec list to see where), and changing python.exe to pythonw.exe, so that the kernel doesn't need a console. I'm not sure how best to fix it generally, though.

MuchInLearning commented 6 years ago

Thank you @takluyver . I was able to solve the issue based on your instructions above to @richardwmcgovern

richardwmcgovern commented 5 years ago

Thanks @takluyver. When I run jupyter kernelspec list it outputs this:

Available kernels: python3 C:\Users\Richard\Anaconda3\lib\site-packages\ipykernel\resources fastai2 C:\Users\Richard\AppData\Roaming\jupyter\kernels\fastai2

I normally use the "Python (default)" kernel. Which has path to executable: C:\\Users\\Richard\\Anaconda3\\python.exe

Unfortunately I can't find a kernel.json file in either the python3 kernel directory, nor my Anaconda3 folder. I do have one in fastai2, but I never use this kernel. Creating a "python3" folder in Roaming/jupyter/kernels/... doesn't work.

Do you know where the default python kernel directory might be on Windows 10?

ErikVini commented 5 years ago

I know this answer is a little late, but in my system the kernel.json file is at (Anaconda Install Dir)\share\jupyter\kernels\python3\, which is the directory that appears when I run the jupyter kernelspec list command in Anaconda Prompt.