notebook icon indicating copy to clipboard operation
notebook copied to clipboard

Resetting notebook_dir on Windows doesn't work

Open zeka0 opened this issue 7 years ago • 19 comments

Gone desperate, searched the issues but found nothing... so I opened this issue. I want to reset the starting directory for Jupyter Notebook, I googled that by doing: in C:\Users\username.jupyter\jupyter_notebook_config.py Change line #c.NotebookApp.notebook_dir = '' to c.NotebookApp.notebook_dir = 'your path'.

However, I have tried using r'my path', "my path", or simply escape the '' in the path string, nothing happened, Jupyter still starts at the user's home directory. Any ideas?

zeka0 avatar May 09 '17 12:05 zeka0

What path are you trying to set it to? Can you show the exact line from your config file? Have you uncommented it?

takluyver avatar May 10 '17 15:05 takluyver

I have tried as follows: (1) c.NotebookApp.notebook_dir = r'E:\Projects\JupyterNotebook' (2) c.NotebookApp.notebook_dir = 'E:\Projects\JupyterNotebook' (3) c.NotebookApp.notebook_dir = 'E:\Projects\JupyterNotebook\' (4) c.NotebookApp.notebook_dir = "E:\Projects\JupyterNotebook"

I have uncommented it, these 4 lines are above are just complete lines I put in that file. All above didn't work.

zeka0 avatar May 10 '17 16:05 zeka0

As far as I can tell you're doing the right thing. It works on my system. Maybe there's an issue with Windows paths. Can you try with forward slashes / instead of backslashes? I know backslashes are correct on Windows, but Python lets you use forward slashes, and it might behave differently.

takluyver avatar May 10 '17 17:05 takluyver

Also, do you have the latest version of the notebook package? If not, try updating it.

takluyver avatar May 10 '17 17:05 takluyver

Changing backslashes to forward slashes didn't work. The thing I didn't mention is that I used Anaconda3 on my windows, and it includes IPython and Jupyter Notebook. I tried using 'conda update jupyter' but it says it's already compatible. Below is a screenshot: default

zeka0 avatar May 11 '17 02:05 zeka0

Try conda update notebook traitlets jupyter_core.

takluyver avatar May 11 '17 10:05 takluyver

Doesn't work. It shows: default

zeka0 avatar May 12 '17 03:05 zeka0

Okay I think I got something. It's the shortcut provided by the Anaconda that is mal-functioning. Jupyter notebook works as intented(start in the right working directory) when fired up using cmd, but it defaults to your home directory when using that shortcut.

zeka0 avatar Jul 13 '17 00:07 zeka0

I guess the Anaconda shortcut is overriding the config. We don't control that shortcut, so you'll need to ask Anaconda about it: https://github.com/ContinuumIO/anaconda-issues/

takluyver avatar Jul 13 '17 07:07 takluyver

@zeka0 I found that you have to add two slashes in Windows for it to work.

c.NotebookApp.notebook_dir = 'E:\\Projects\\JupyterNotebook'

tylerkoldenjtp avatar Apr 05 '18 23:04 tylerkoldenjtp

I have found solution for this issue : Step-1 : Open Jupyter Notebook shortcut location from start Menu Step-2 : Go to properties of that shortcut Step-3 : In the Target Section, replace "USERPROFILE" with "Jupyter"

Now Jupyter Notebook using that shortcut will also open in the intended location. (Location as given in the file jupyter_notebook_config.py)

padamsinghinda avatar Jun 01 '18 16:06 padamsinghinda

  1. Execute jupyter notebook --generate-config
  2. Open the file generate in the location C:\Users\username.jupyter\jupyter_notebook_config.py
  3. Used double slashes to update the file c.NotebookApp.notebook_dir = 'C:\Projects\JupyterNotebook'

JavierMedel avatar Jul 17 '18 17:07 JavierMedel

I have found solution for this issue : Step-1 : Open Jupyter Notebook shortcut location from start Menu Step-2 : Go to properties of that shortcut Step-3 : In the Target Section, replace "USERPROFILE" with "Jupyter"

Now Jupyter Notebook using that shortcut will also open in the intended location. (Location as given in the file jupyter_notebook_config.py)

Jupyter will crash on my computer if I replace "USERPROFILE" with "Jupyter". But if you just delete %USERPROFILE%, Jupyter will work fine. image image

songquanpeng avatar Jun 09 '19 02:06 songquanpeng

Consolidating above steps suggested on what worked for me using Windows 10 : Update Anaconda settings:

  1. Launch the command prompt from Anaconda by clicking on “Open Terminal” (from any environment)
  2. The enter the following command : jupyter notebook --generate-config, and wait a few seconds to create a file named “jupyter_notebook_config.py” in your user folder.
  3. Open "jupyter_notebook_config.py" file and search for “#c.NotebookApp.notebook_dir = ' ' ‘‘
  4. Remove the comment and add your desired path inside quotes with double slashes (\). Suppose I want to point it to E drive, it would look like this: c.NotebookApp.notebook_dir = 'E:\'
  5. Save it and done with Anaconda. You can stop here, if you don't use any shortcut icons.

Update the Anaconda icon:

  1. Open Jupyter Notebook shortcut location from start Menu
  2. Go to properties of that shortcut
  3. In the Target Section, delete "USERPROFILE" from the entire path and remove anything in the Start in: box

Hope that helps.

Rajesh16702 avatar Feb 18 '20 02:02 Rajesh16702

Hi guys,

I run into similar issues. I use anaconda 1.9.12. I am able to change the default directory in jupyter_notebook_config.py and it works fine if I start from anaconda. The shortcut overwrites the jupyter_notebook_config.py settings and starts in the default folder. When checking the properties of the shortcut I don't have USERPROFILE and my Start in box says %HOMEPATH% -> If I change anything in Start in box then the shortcut breaks even if I put %HOMEPATH% back.

Any idea what else I could try?

Many thanks

Tom Capture

tomnewg avatar Mar 15 '21 04:03 tomnewg

I have found solution for this issue : Step-1 : Open Jupyter Notebook shortcut location from start Menu Step-2 : Go to properties of that shortcut Step-3 : In the Target Section, replace "USERPROFILE" with "Jupyter" Now Jupyter Notebook using that shortcut will also open in the intended location. (Location as given in the file jupyter_notebook_config.py)

Jupyter will crash on my computer if I replace "USERPROFILE" with "Jupyter". But if you just delete %USERPROFILE%, Jupyter will work fine. image image

I just delete %USERPROFILE% and Jupyter will work fine . Thanks!

zhangchile avatar May 31 '21 11:05 zhangchile

I found a "problem", which has to do with anaconda specifically. Original issue - jupyter notebook wouldn't change the directory, even if I change the location in the config files. As well as simply executing jupyter notebook in cmd gives an error about a DLL failing to load. The problem is the environment - if you run activate.bat under [install location]/Anaconda3/Scripts in the command prompt and then execute the same command, it loads the notebook location properly. Looks like Anaconda's implementation of python as such. If you have multiple environments, you probably know more than I do on the topic. The configs also work if jupyter notebook is launched from anaconda navigator. image EDIT: You can also run the command conda activate base after having run conda init https://stackoverflow.com/questions/69468117/how-to-activate-anaconda-environment (not a lot of information here, but this just tipped me that way)

DZHEX avatar Oct 25 '21 15:10 DZHEX

jupyter notebook --notebook-dir [LOCATION] as a workaround i guess....

roflbofl322 avatar Jan 23 '22 10:01 roflbofl322

@zeka0 I found that you have to add two slashes in Windows for it to work.

c.NotebookApp.notebook_dir = 'E:\\Projects\\JupyterNotebook'

This one works, thanks

backjoao88 avatar May 08 '22 02:05 backjoao88

I have the same request. Clearly speaking, is it possible to use Environment Variable(e.g. HOME) in c.NotebookApp.notebook_dir? Apparently, using the envvar in the config file will cause the crashing of jupyter book.

easior avatar May 31 '23 12:05 easior