56

I installed Anaconda on my Windows 10 machine.

I have a few Jupyter notebooks on my pc and I would like to associate them with Jupyter, so they can be opened by double-clicking on the file, to avoid having to open Jupyter and navigate to the notebooks folders each time. Is this possible?

All notebooks should open in the same Jupiter Kernel (same localhost in the browser address bar), without starting a new kernel for every file I click.

PS I asked here because I figured this question to be more of interest for programmers, but if you think it would be more suited for SuperUser, I'll flag it for migration.

divenex
  • 15,176
  • 9
  • 55
  • 55
DeltaIV
  • 4,773
  • 12
  • 39
  • 86
  • 1
    I don't think it would be possible to double-click on an ipynb file and have it start a Jupyter Notebook server and open the file. If it is possible, I think you would have to create a separate batch script that is associated with the ipynb files, and in that batch script, start the Jupyter Notebook. It would probably be easier to open the Anaconda Prompt, cd to the directory with the files, and then start the Jupyter notebook. – darthbith Nov 13 '17 at 20:52
  • @dartbith that's what I've been doing (opening the Anaconda prompt, cd to the ipnyb dir & execute `jupyter notebook`). I was looking for alternatives, but apparently there aren't any. – DeltaIV Nov 13 '17 at 21:30
  • 1
    You could create a copy of the shortcut to the Anaconda Prompt and change the "Start in" folder for the copied shortcut. At least then you wouldn't have to do the cd step. Unfortunately, I'm not on Windows at the moment so I can't check that this would work. – darthbith Nov 13 '17 at 23:42
  • @darthbirth checked on Windows and it works. A bit annoying because I have to create a copy of the shortcut for each Jupyter project folder, but I don't work on more than one notebook project at the same time, so it's ok (I much prefer to use a real IDEs such as PyCharm to develop Python code, Jupyter is mostly for communication/reporting). – DeltaIV Nov 14 '17 at 14:41
  • 1
    ** Solution is given by @endolith in an answer below **. Not yet marked as correct, but it is correct. – ProfDFrancis Apr 21 '19 at 17:15
  • Hi. Have you found a solution for this yet? Could you please share your findings? Thank you – Confounded Jul 22 '21 at 12:39

8 Answers8

71

Install nbopen: https://github.com/takluyver/nbopen

pip install nbopen
python -m nbopen.install_win

Now you can double-click on *.ipynb files:

Example.ipynb icon in Windows 7

endolith
  • 25,479
  • 34
  • 128
  • 192
  • Thanks. I'll test this in the next days and accept your answer once I get confirmation that it works for me. – DeltaIV Jan 22 '18 at 17:48
  • @DeltaIV I'm using Anaconda with Python 3, by the way. – endolith Jan 22 '18 at 18:07
  • 1
    Amazing - works for me. Windows 10. Anaconda, Python 3. @DeltaIV you should mark this as correct. – ProfDFrancis Apr 21 '19 at 17:13
  • 4
    for me, i first have to activate at least base virtual env before running jupyter notebook., how do I achieve this double click functionality in that case? – Parthiban Rajendran Jun 14 '19 at 16:30
  • 1
    I get a 404 error after running that and double-clicking an existing .ipynb – Wassadamo Aug 01 '20 at 00:05
  • 2
    The problem of this solution is that it starts a new Jupiter Kernel (different localhost number in the browser address bar) for every file, instead of reusing an open kernel as it should do. It achieves the same non-ideal results as @fredm73 answer, with much unnecessary complication. – divenex Aug 20 '20 at 09:28
  • Thanks, I changed for `ipython -m nbopen.install_win` and was great – Alex Poma Sep 13 '20 at 02:12
  • This didn't work for me. It does associate but when I click nothing happens. – Ljupcho Naumov Sep 15 '21 at 10:21
24

If you have Jupyter installed with Anaconda you can do the following.

Create a little batch file (e.g. start_jupyter_notebook.bat) with the content (the commands are from the Jupyter shortcut):

@echo off
set ANACONDAPATH=C:\_work\_programs\Anaconda3
%ANACONDAPATH%\python.exe %ANACONDAPATH%\cwp.py %ANACONDAPATH%^
 %ANACONDAPATH%\python.exe %ANACONDAPATH%\Scripts\jupyter-notebook-script.py %1

(of course you will have to change the ANACONDAPATH to your installation)

Then go to one .ipynb file of your choice, right-click on it, go to properties --> open with --> change and select your created batch file.

I am pretty sure this can also be setup for any other Python/Jupyter installation.

P.S. The cwp.py file sets up some environment variables. I guess this is the reason why fredm73's answer did not work for everybody. Apart from that my answer is quite similar in the end.

schendi
  • 271
  • 2
  • 3
  • 2
    This solution works like a CHARM! It should be way upvoted! – Gustavo Mirapalheta Aug 16 '19 at 02:15
  • This start up jupyter, but does not open the particular notebook. How to have a notebook open in jupyter by double-clicking the IPYNB file? – Confounded Oct 16 '19 at 10:19
  • @Confounded I can double-click a ipynb file and it opens directly following my description. Not sure why it does not work for you. Do you have Anaconda installed? Maybe you can compare your original Jupyter shortcut to what I presented here since I only modified my original Jupyter shortcut a bit. Maybe your setup is different. Did you try running the batch file from a terminal/command line? Does it give any errors? – schendi Oct 18 '19 at 06:46
  • I adapted this to work with an R environment as cd %HOMEPATH% %ANACONDAPATH%\python.exe %ANACONDAPATH%\cwp.py %ANACONDAPATH%\envs\R %ANACONDAPATH%\envs\R\python.exe %ANACONDAPATH%\envs\R\Scripts\jupyter-notebook-script.py %1 – Kirsten Apr 03 '21 at 18:14
  • 2
    For me, it starts a new Jupyter Kernel (different localhost number) for every file. Is it possible to reuse an open kernel instead? – Shradha Jul 02 '21 at 11:59
  • To get this work for me, I had to use pythonw.exe instead of python.exe. Then worked perfectly. I also placed the word "start" before the beginning of the command, and "exit" after it. This ensured that the cmd window did not remain open. I used jupyter-lab-script.py to open with Jupyter Lab instead of Notebook. – Dani Freidus Mar 25 '22 at 11:10
  • This is the one that worked for me, too. I do get a weird message "Could not log you in| at the top of the notebook when I first open it, but you can close it and other than that everything seems to be working. It's weird because I had to resort to this on one laptop, but on another one, directly associated the jupyter-notebook.exe with the ipynb extension worked just fine. – butterflyknife Jun 13 '22 at 13:24
17

associate .ipnyb with jupyter-notebook.exe

On Windows 10: control panel/Programs/Default Programs/Associate a file type or protocol with a program/Choose default apps by file type

Look at the list of extensions, find '.ipnyb'. Click on icon and locate the jupyter notebook program. In my Anaconda installation, it is found at anaconda/scripts/jupyter-notebook.exe

fredm73
  • 347
  • 2
  • 9
  • In case you get a 404 page when trying to open an ipynb file with jupyter-notebook.exe, you need to update Jupyter and Jupyterlab. To do so, run `conda update jupyter` and `conda update jupyterlab` in the command prompt. – Donald Duck Apr 06 '18 at 12:56
  • 5
    Windows no longer seems to allow associating arbitrary programs in that menu. Instead, right-click on the notebook file, click Properties and from there you can set any program to open the file with. At least for now... – HenriV Jul 10 '18 at 08:22
  • It didn't worked for me with Win10 and Anaconda, Python 3.7 – user1889297 Nov 20 '18 at 06:19
  • It didn't worked for me either with Win10 and Anaconda, Python 3.7 – qqqwww Mar 19 '19 at 14:37
  • The solution from schendi works like a charm. Please look at it. – Gustavo Mirapalheta Aug 16 '19 at 02:18
  • 1
    The problem of this solution is that it starts a new Jupiter Kernel (different localhost number in the browser address bar) for every file, instead of reusing an open kernel as it should do. – divenex Aug 20 '20 at 08:46
10

Easiest way for me - double click on the .ipnyb file. When prompted to pick a program to open the extension with go to /ProgramData/Anaconda3/Scripts and locate the jupyter-notebook.exe file and click it.

NOTE - to access the ProgramData folder you will need to view hidden folders in the Windows explorer or access it by typing %programdata% in the navigation line:

enter image description here

Amir F
  • 2,431
  • 18
  • 12
  • This worked on my Windows, thanks! Is there such an easy way to set this up also on Ubuntu? – NeStack Jan 18 '20 at 09:31
  • it works, thanks a lot, you only need to do it once and it is applied to all the .ipynb files, no extra software or library required for it. (but may some PATH needs to be setup) – user3065757 Jun 22 '20 at 17:13
  • 1
    The problem of this solution is that it starts a new Jupiter Kernel (different localhost number in the browser address bar) for every file, instead of reusing an open kernel as it should do. – divenex Aug 20 '20 at 08:44
  • @divenex Do you have a solution for this? Such that double-clicking on an note-book file in Windows open the notebook in the same Kernel? Without having to install third-party tools. Thank you – Confounded Jul 22 '21 at 12:36
  • No solution, I would have given it here. And even installing `nbopen` makes no difference and still opens a different kernel for me. – divenex Jul 23 '21 at 16:55
  • Hi, I have done this process but unable to achieve the same. Is there anything else need to be done here with environment path? @user3065757 if you have any suggestion please help. I have environment variables to my system where the Anaconda Scripts folder is present. – Shaikh Naushad Feb 17 '22 at 08:50
3

You can use nbopen on pip and run the module:

py -m pip install -U nbopen
py -m nbopen.install_win
RGBCube
  • 82
  • 5
1

For those who installed nbopen in Anaconda but it does not work:

Use Regedit to search for a directory called Jupyter.nbopen, and navigate to its shell\open\command. It should be something like:

HKEY_USERS\****\Software\Classes\Jupyter.nbopen\shell\open\command

Then, change the default to: (Modify the path if you are not installed in default location)

"C:\ProgramData\Anaconda3\pythonw.exe" "C:\ProgramData\Anaconda3\cwp.py" "C:\ProgramData\Anaconda3" "C:\ProgramData\Anaconda3\pythonw.exe" -m nbopen "%1"

The reason behind this is that cwp.py makes sure that the Jupyter is running in Anaconda instead of other Python environments.

Then it should work, although it will activate two invisible pythonw process running in the background.

wdhwg001
  • 31
  • 1
1

Just look into your file directory and look for programs that can open the file type and set it as your default app opener but you need to take into consideration that if you want to use Jupiter notebook, you can run jupyternotebook app and locate the file from the jupyter notebook directory.

Secondly, ensure you have added your python.eex to path and run directly from your command prompt. See pictures in the screenshot running a py file in my downloads directory

Randomize
  • 8,651
  • 18
  • 78
  • 133
0

Find the jupter-notebook.exe in the C:\Users\my_username\Anaconda3\Scripts folder. Copy the address. When you're opening the .ipnyb file double click ( if first time) or just do open with and there in the menu you can tick the 'always use this' option and locate the notebook from 'look more programs' option in the menu.