Jupyter notebook file directory, how to change

As per
https://app.dataquest.io/m/349/project%3A-learn-and-install-jupyter-notebook/8/installing-jupyter-locally
and subsequent pages I have installed Anaconda locally and launch Jupyter Notebook from there.

I started experimenting with creating something simple (say, ‘Hello World’) and running/saving it. I noticed that it saves things in C:\Users\myusername

Going forward, I don’t think I want to keep things there, but would e.g. want to organize projects in something like E:\MyDataquestProjects… With my initial experiments in something like E:\MyDataquestProjects\SandPit\ and guided projects in something like E:\MyDataquestProjects\someprojectname…
And then with subfolders for code, data, etc.

The question that I have is how to set it up like that in the easiest way. There is no “Save as” option when saving a notebook. I have been googling a bit, and do find articles related to this. E.g.


And suggestions to start up Notebook from the desired folder in the first place. (How?)

All this seems a bit cumbersome and ‘low level’ though… Do I in 2020 really have to go to command-boxes, type in commands there, just to organize my work in folders, etc.? So I was wondering whether there is any best practice for this.

Hey, Jasper.

There may be more user friendly ways by using extensions, but I think it is worth it to dive into what’s really happening here.

Every time you run a program, it has a starting directory. When you start up a media player, it has a starting directory. When you start up your web browser, it also has a starting directory. This is at the heart of what’s happening here.

The reason why you can only save notebooks (or access any files) in C:\Users\myusername is because you’re starting Jupyter from this directory, and Jupyter only always you to access files in the directories or subdirectories where it starts.

The post you shared teaches how to change the default startup directory, which might the least effort solution.

Personally, what I do is start Jupyter from the directory that is convenient to me at the moment. To do this just fire up a terminal, navigate into the directory from which you want to start Jupyter and run jupyter-lab.

Let me know if you have any additional questions.

Hi Bruno,

Thank you for the reply and suggestion. With a bit of struggle, I got this to work.

I did not get this to work from a ‘regular’ command box. When trying I get the error " ‘jupyter’ is not recognized as an internal or external command, operable program or batch file." after switching to my desired work directory.

Only when I open the ‘Anaconda prompt’ (which I found under the Start menu after installing Anaconda) and try it from there, this appears to work. So that’s like this:

I must say it feels a bit cumbersome though. Did I make a mistake? And/or maybe I should figure out whether I can put all these commands that I now have to type in ‘one click’, but I am not fully sure how to do that.

Anyway, seems I can continue with the ‘actual’ work.

Anaconda Prompt has some additional settings that lead to the behavior you experienced. You can learn about some closely related things in the command line course in the last step of the Data Scientist in Python path.

I’ll explain this specific phenomenon here. Open a command line window (either the regular one, or Anaconda Prompt) and run, for example, explorer. A Windows Explorer window should pop up.

If you run jupyter-lab (or notebook, if you prefer), you run into the issue you mentioned, where it works in Anaconda Prompt, but not in the regular command line.

So what’s the difference between explorer and jupyter-lab? It has to do with the additional settings I mentioned, specifically the value stored in the environment variable PATH. You can think of environment variables as settings in the operating system (a rough, but sufficient simplification for our purposes here).

Try running PATH in a regular command line window and in Anaconda Prompt. You’ll see that PATH is a list of directories. From its Wikipedia page:

PATH is an environment variable (…) specifying a set of directories where executable programs are located.

Now look back at the outputs of running PATH in each window. It most likely is the case that the one in Anaconda Prompt has some more directories. One of these directories includes the program jupyter-lab, and that’s why you get an error in the regular command line window, and not in Anaconda Prompt.

What is cumbersome? Opening Anaconda Prompt and launching Jupyter from there?

Do you want a shortcut for Jupyter that launches it from D:/DataProjects? I think I’ve done something similar once, but I’ll have to look into it again. Let me know if that’s what you want so I can investigate.

Hi Bruno,
Thanks again for you fast and detailed response. Tried out the PATH thing, makes sense now, thanks for explaining.
As for the ‘what is cumbersome’, I meant indeed the opening of the prompt, changing folders, typing ‘jupyter notebook’ in full etc. Obviously not a big deal; I just grew up more with clickable icons in windows and less with typing commands in command boxes :grinning:. Which made me curious whether that cannot be simpler. But anyway, I’m good now, no need to look it up. (I actually also in the meantime tried out the other solution, with changing the start default start path for Jupyter via Anaconda, as per the article that I linked to. Also works.)
And although learning this configuration-stuff is also useful I guess, let me now shift back my focus again to learning data analysis in Python :grinning:.

1 Like