When I first started using notebooks, one of the letdowns was that I wasn’t able to navigate upwards out of the installation folder. I save all my projects on an extra internal hard disk drive, both for safety and portability. It’s also never a bad idea to have an additional backup (besides GitHub). Accessing these projects through my (Anaconda) Jupyter Notebooks seemed to be impossible. However, several solutions have been proposed on StackOverflow and other boards. Here’s a quick overview.
Throughout this blog post I’ll be using D:/python/foo as project folder. My Anaconda environment is data_science.
Solution 1: navigate to the folder and run Jupyter
The first solution is straightforward. You simply activate your environment, you browse to your project folder in the Anaconda Prompt, and you run Jupyter notebooks. It’s not a one-time solution. Every time you want to work on your project, you’ll have to retake these steps.
activate data_science d: cd python/foo jupyter notebook
Solution 2: set the notebook-dir parameter
A faster solution (just one line of code) is to set the notebook-dir parameter when starting Jupyter notebook.
jupyter notebook --notebook-dir=D:/python/foo
Solution 3: edit the configuration file
A more permanent solution is editing the Jupyter configuration file. By running the following command in your Anaconda prompt, a file will be created (jupyter_notebook_config.py in your Jupyter installation folder).
jupyter notebook --generate-config
In this file, you’ll find c.NotebookApp.notebook_dir after a hash. Uncomment the line by removing the hash and set the value to the directory of your projects.
c.NotebookApp.notebook_dir = 'D:\python'
Now run Jupyter Notebook from the Anaconda prompt (or the Navigator), and you’ll start from your preferred directory. Keep in mind that you’ve changed the directory for every environment.
Another nuisance solved!