{"id":157,"date":"2019-08-22T12:15:50","date_gmt":"2019-08-22T12:15:50","guid":{"rendered":"https:\/\/openapex.org\/spaces\/software\/?p=157"},"modified":"2023-01-31T10:45:51","modified_gmt":"2023-01-31T05:15:51","slug":"start-jupyter-notebook-in-the-background-and-with-a-custom-working-directory","status":"publish","type":"post","link":"https:\/\/mutesoft.com\/spaces\/software\/start-jupyter-notebook-in-the-background-and-with-a-custom-working-directory.html","title":{"rendered":"How to Change Working Directory in Jupyter Notebook"},"content":{"rendered":"\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"628\" src=\"https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/02\/jupyter-notebook.png\" alt=\"Jupyter notebook\" class=\"wp-image-1048\" srcset=\"https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/02\/jupyter-notebook.png 1200w, https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/02\/jupyter-notebook-300x157.png 300w, https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/02\/jupyter-notebook-1024x536.png 1024w, https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/02\/jupyter-notebook-768x402.png 768w, https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/02\/jupyter-notebook-500x262.png 500w, https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/02\/jupyter-notebook-800x419.png 800w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><figcaption class=\"wp-element-caption\">Jupyter notebook<\/figcaption><\/figure>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_79_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\"><p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<\/div><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/mutesoft.com\/spaces\/software\/start-jupyter-notebook-in-the-background-and-with-a-custom-working-directory.html\/#1_Installing_Jupyter_Notebook\" >1. Installing Jupyter Notebook<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/mutesoft.com\/spaces\/software\/start-jupyter-notebook-in-the-background-and-with-a-custom-working-directory.html\/#2_Start_Notebook_in_the_background\" >2. Start Notebook in the background<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/mutesoft.com\/spaces\/software\/start-jupyter-notebook-in-the-background-and-with-a-custom-working-directory.html\/#3_Start_Notebook_with_a_custom_working_directory_for_a_single_session\" >3. Start Notebook with a custom working directory for a single session<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/mutesoft.com\/spaces\/software\/start-jupyter-notebook-in-the-background-and-with-a-custom-working-directory.html\/#4_Start_Notebook_with_a_custom_working_directory_always\" >4. Start Notebook with a custom working directory always<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"1-installing-jupyter-notebook\"><span class=\"ez-toc-section\" id=\"1_Installing_Jupyter_Notebook\"><\/span><strong>1. Installing Jupyter Notebook<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Use <code>pip<\/code> or <code>conda<\/code> (<code>Anaconda<\/code>) to install Jupyter Notebook, if not installed already.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"atomic\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Python 3\npython3 -m pip install jupyter\n\n#Python 2\npython -m pip install jupyter<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"2-start-notebook-in-the-background\"><span class=\"ez-toc-section\" id=\"2_Start_Notebook_in_the_background\"><\/span><strong>2. Start Notebook in the background<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>When the <code>notebook<\/code> command is executed, the server starts and a browser window is opened. The default working directory is the user&#8217;s home directory.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"atomic\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Start notebook normally\njupyter notebook\n\n# Start notebook and run in the background\njupyter notebook &amp;> \/dev\/null &amp;<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3-start-notebook-with-a-custom-working-directory-for-a-single-session\"><span class=\"ez-toc-section\" id=\"3_Start_Notebook_with_a_custom_working_directory_for_a_single_session\"><\/span><strong>3. Start Notebook with a custom working directory for a single session<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Add the option <code>--NotebookApp.notebook_dir<\/code> to specify a working directory while starting the <code>Notebook<\/code>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"atomic\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">jupyter notebook --NotebookApp.notebook_dir=\/Users\/abc\/Work\/python\n\n# You'll see a message like the following\n# [I 11:47:46.507 NotebookApp] Serving notebooks from local directory: \/Users\/abc\/Work\/python<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"4-start-notebook-with-a-custom-working-directory-always\"><span class=\"ez-toc-section\" id=\"4_Start_Notebook_with_a_custom_working_directory_always\"><\/span><strong>4. Start Notebook with a custom working directory always <\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In case you want to always start the <code>Notebook<\/code> with a specific working directory, instead of specifying it as an option in the shell command, you can specify the working directory in the config file. <\/p>\n\n\n\n<p>Generate the config file if it does not exist. The typical location of the config file on Mac: <code>~\/.jupyter\/jupyter_notebook_config.py<\/code>.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"atomic\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Generate a config file if not existing already\njupyter notebook --generate-config\n\n# Creates the folloiwng file\n# ~\/.jupyter\/jupyter_notebook_config.py\n\n# Modify the following key in the config file to specify the desired working directory\nc.NotebookApp.notebook_dir = '\/Users\/abc\/Work\/python'\n\n# Start notebook normally\njupyter notebook\n\n# Or start notebook in the background\njupyter notebook &amp;> \/dev\/null &amp;<\/pre>\n\n\n\n<p><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article shows how to change the working directory of Jupyter Notebook temporarily for a single session or permanently.<\/p>\n","protected":false},"author":2,"featured_media":1048,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"none","_seopress_titles_title":"","_seopress_titles_desc":"This article shows how to change working directory of Jupyter Notebook temporarily for a single session or permanently.","_seopress_robots_index":"","_vp_format_video_url":"","_vp_image_focal_point":[],"footnotes":""},"categories":[32],"tags":[48,10,36],"class_list":["post-157","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tools","tag-jupyter-notebook","tag-python","tag-tools"],"_links":{"self":[{"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/posts\/157","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/comments?post=157"}],"version-history":[{"count":19,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/posts\/157\/revisions"}],"predecessor-version":[{"id":1415,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/posts\/157\/revisions\/1415"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/media\/1048"}],"wp:attachment":[{"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/media?parent=157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/categories?post=157"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/tags?post=157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}