18

After installing Anaconda, the Jupyter notebook shortcut works fine. Other stackoverflow answers have indicated that you can change the default working directory by changing the "Start In:" field in the shortcut properties. However, if Anaconda is installed in the suggested folder for single users C:\Users\whshg0\AppData\Local\Continuum\Anaconda3\, then the Target field of the shortcut gets truncated when you edit the Start in field. Example:

C:\Users\user01\AppData\Local\Continuum\Anaconda3\python.exe C:\Users\user01\AppData\Local\Continuum\Anaconda3\cwp.py C:\Users\user01\AppData\Local\Continuum\Anaconda3 "C:/Users/user01/AppData/Local/Continuum/Anaconda3/python.exe" "C:/Users/user01/AppData/Loc

al/Continuum/Anaconda3/Scripts/jupyter-notebook-script.py" gets truncated. After you click ok, Jupyter Notebook will no longer open.

What is a fast way to rebuild the Jupyter Notebook shortcut so the Target is not limited to the 255 character limit?

Clay
  • 2,019
  • 18
  • 43
  • 2
    your question is my answer. Thanks for specifying what the rest of the command line was supposed to be. :) – daveloyall Dec 05 '16 at 20:14

8 Answers8

10

I was able to remake the shortcut by pointing the shortcut to:

C:\Users\user01\AppData\Local\Continuum\Anaconda3\Scripts\jupyter-notebook.exe

I lost the icon but I'm sure with some searching I can find it again.

β.εηοιτ.βε
  • 16,236
  • 11
  • 41
  • 53
Matt Camp
  • 1,127
  • 2
  • 13
  • 31
  • I reinstalled in a lower directory so I don't have that problem any more. – Clay May 12 '16 at 22:30
  • 1
    Why not just have that as the default anyway? What is the point of `jupyter-notebook-script.py`, `python.exe`, and `cwp.py`? Some of them are repeated in quotes and not in quotes. A side effect of starting the `jupyter-notebook.exe` directly, is that whatever directory you call it from automatically becomes your working directory. I have not found any detriments to not using the default `Target`. – Clay May 12 '16 at 22:36
7

In Environment variables create System variable Anaconda3 (or other name) with the value:

C:/Users/user01/AppData/Local/Continuum/Anaconda3

Then substitute first 3 entries of:

C:/Users/user01/AppData/Local/Continuum/Anaconda3

in Shortcut -> Target with %Anaconda3%. This will make the target line length < 255.

Peter Badida
  • 7,432
  • 8
  • 33
  • 74
Leo
  • 71
  • 1
  • 2
  • 1
    I believe you could also use the pre-existing variable %localappdata% to substitute for C:\Users\user01\AppData\Local, and the line will still be short enough (barely). – Tim Goodman Jul 15 '18 at 01:58
  • By swapping the forward slashes for backward slashes, I was able to also substitute the quoted entries with the new environment variable name – Oly Apr 07 '19 at 18:57
3

The cleanest way I found to change the default working directory is to edit the cwp.py file in the Anaconda folder as following (at the end of the file):

Replace this line:

os.chdir(documents_folder)

with the folder you want to start in:

os.chdir("C:\\Private_Files\\MachineLearning")

3

I installed miniconda instead of Anaconda because i was tired of anaconda crashing while updating. So anaconda prompt and jupyter notebook shortcuts had to be built manually.

For Anaconda Prompt, the shortcut:

  • Target: C:\Windows\System32\cmd.exe "/K" "%Localappdata%\Continuum\miniconda3\Scripts\activate.bat"
  • Start in: my preferred start location, eg C:\users\me\Onedrive\Projects

For Jupyter notebook, the shortcut:

  • Target: %localappdata%\Continuum\miniconda3\python.exe %LocalAppData%\Continuum\miniconda3\cwp.py %LocalAppData%\Continuum\miniconda3 "%LocalAppData%\Continuum\miniconda3\python.exe" "%LocalAppData%\Continuum\miniconda3\Scripts\jupyter-notebook-script.py"
  • Start in: didn't matter (see below)

(Replace miniconda3 with Anaconda3). Pointing to jupyter-notebook.exe as people suggested above did not work unless I was an activated environment, which I was not with a desktop shortcut.

Unfortunately setting the Start In field did not open jupyter in that folder, so maybe step 2 is @Bellaiche's suggestion. I followed the instructions here to set the Jupyter startup folder: How to change the Jupyter start-up folder.

Added the shortcuts to %appdata%\Microsoft\Windows\Start Menu\Programs\Anaconda3 just to have them on the start menu.

1

FYI I found another issue with the shortcut on Windows 7. The Target string of the Jupyter Notebook start menu item had a %HOME% argument at the end. (a) There is no %HOME%, but there is a%HOMEPATH%, so change it to that if you want to start in your home directory. (b) An alternative way to specify the start up directory is to use the Start In field in the Properties dialog box (http://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/execute.html). To do it the latter way, remove the final path argument from Target.

v.chaplin
  • 467
  • 3
  • 5
  • I think this should be an answer. Because the problem is correctly identified as "%HOME%". Also, editing cwp.py 1) requires locationg the file and 2) might corrupt the script file during the editing. In my opinion, changing Windows Shortcut Target property arguments as suggested is cleaner and safer way. – seongjoo Mar 06 '17 at 05:59
0

I have tried to shorten path by defining my own %anaconda3% variable but my prompt opens and closes within 1 second if i ever edit the target or start in fields. of shortcut properties.

According to https://medium.com/@joelclay/access-your-jupyter-notebook-running-on-windows-10-from-any-computer-427bb06309ce the contents of target are C:\Users\joel\Anaconda3\python.exe C:\Users\joel\Anaconda3\cwp.py C:\Users\joel\Anaconda3 “C:/Users/joel/Anaconda3/python.exe” “C:/Users/joel/Anaconda3/Scripts/jupyter-notebook-script.py” I am careful to leave space between the lines and see that last 2 of them are strings with reversed slashes.

Finally my hack was to create a .bat file containing %anaconda3%\scripts\activate.bat & jupyter notebook and put this bat file in my jupyter shortcut target so it does the same thing as opening Anaconda Prompt and typing jupyter notebook

Han Qi
  • 1
  • 1
  • 3
0

The problem was resolved. The shortcut was the issue.

I had to manually change the "Shortcut target" to the following:

C:\Users\'yourusername'\AppData\Local\Continuum\Anaconda3\Scripts\jupyter-notebook.exe

Martin
  • 14,189
  • 1
  • 26
  • 43
-1

Change c.NotebookApp.notebook_dir = '' to desired directory.

It will work from Anaconda prompt, but will not with a shortcut. Originally shortcut is too big, that big, that it gets truncated. Actually with jupyter running we don't need cwp.py because the paths assigned there are useless in our case. Change the target of a shortcut to:

C:\Users\USER\AppData\Local\Continuum\Anaconda3\python.exe "C:/Users/USER/AppData/Local/Continuum/Anaconda3/Scripts/jupyter-notebook-script.py"

Change USER to user on your computer, don't forget to change backslash to forward slash in an argument.

Shadow
  • 30,859
  • 10
  • 44
  • 56
DiMithras
  • 31
  • 4