How to Open Jupyter Notebook in Desired Folder in Anaconda

Jupyter notebook is a useful tool to work with data and easy visualization purposes which most people use with the Anaconda environment. But by default, its root directory is the C drive of the pc, and often we need to work in a different directory. Unlike spyder, you can not find any option of directory change in jupyter interface. We have to do it manually via the command prompt or the anaconda prompt. Further we can make a batch file to bypass the hassle of writing commands repeatedly in the command prompt. These three options are discussed below. But at first, create a folder in a directory where you want to save the code files. I have created a folder named "jupyter_notebook_all_codes" in my G directory like this:


Notice that, the folder path is 
G:\jupyter_notebook_all_codes

Now let's explore the three options.

Option 1: Via the Anaconda Prompt:

In the anaconda prompt, first, enter a command to go to the desired directory ( In my case, the G directory). After that, enter the command cd (change directory), put a space, and write your desired folder path(In my case,G:\jupyter_notebook_all_codes)to change the default directory to the desired folder. Finally, write a command to open the jupyter notebook from there. The whole process is shown in the following picture.


Here, the first line takes to the G directory. The  second line changes the default directory to the desired folder. Finally from this folder, jupyter notebook is launched.

Option 2: Via the command prompt:

Anaconda prompt actually opens a batch file named "activate.bat"(batch file is basically the collection of command prompt line, executed one after another), which resides in the script folder of anaconda 3 in your pc. For example, in my pc, the location of this batch file is as shown in the following picture:


It is very important to find the location of this batch file. In my pc, the location is, therefore:

C:\Users\rafe\anaconda3\Scripts\activate.bat

Notice that, the path may be different on your pc.

Now, open the command prompt and call this batch file. This will lead you to the situation of option 1 like this:

Now, just repeat the commands of option 1 to open the jupyter notebook.

Option 3: Via creating a batch file:

As it is difficult to remember the commands as well as writing it every time, we can bypass this lengthy process by creating a batch file. At first, create a text file in your desired folder ( In this example case, jupyter_notebook__all_codes folder). After that, copy the following commands in that file:

call C:\Users\rafe\anaconda3\Scripts\activate.bat
jupyter notebook
pause

Here, the first line calls the activate.bat file from the anaconda script (which may vary according to your pc mentioned above).The second line runs the jupyter notebook in the desired folder. The third line is optional, it is inserted to freeze the command prompt window.

(Notice that here the cd command isn't provided, as the text or batch file is already in the desired directory. We just need to run the jupyter notebook from here).

Change the extension of the text file as .bat from .txt. Select the file type as "All files", which will create both the batch and the text file. 

So, run this batch file every time you want to open the jupyter notebook in your desired folder.

Additional FAQ for the beginner:

How to open anaconda command prompt (option 1)?
open the start menu and type anaconda prompt

How to open windows command prompt (option 2)?
open the start menu and type cmd







Comments