0

I have a notebook instance with a startup script that uses papermill to execute a notebook. The problem is that the working directory is '/' and not the path of the file. How do I get the path of the file so I can set it as the working directory?

This is how I update my script:

gcloud... --metadata startup-script="/opt/conda/bin/papermill /home/jupyter/some_dir/mynotebook.ipynb /home/jupyter/some_dir/out1.ipynb"
gogasca
  • 9,283
  • 6
  • 80
  • 125
Rony Tesler
  • 1,207
  • 15
  • 25
  • normally you want to use full paths for referencing files. Can you share the example command ? Example: papermill gs://my-bucket/test.ipynb /tmp/test.ipynb – gogasca Dec 04 '20 at 04:27
  • Can you share the startup script/command that you are executing? – DavicC Dec 04 '20 at 08:54
  • @gogasca ... --metadata startup-script="/opt/conda/bin/papermill /home/jupyter/some_dir/mynotebook.ipynb /home/jupyter/some_dir/out1.ipynb". So the notebook is run, but when it's run, its working directory is '/'. – Rony Tesler Dec 04 '20 at 17:02
  • @DavicC shared it in the post – Rony Tesler Dec 04 '20 at 17:03
  • 1
    I'm not sure I fully understand your question, where is the input notebook? and where do you want the output notebook to be? what error do you get? Anyways check this post with a script (notebook_executor.sh) I wrote a while back: https://towardsdatascience.com/how-to-use-jupyter-on-a-google-cloud-vm-5ba1b473f4c2 – gogasca Dec 04 '20 at 19:06
  • @gogasca my script is executed, but its working directory is '/' and I want it to be the notebook's path (/home/jupyter/some_dir) in my case. – Rony Tesler Dec 04 '20 at 19:17
  • 1
    You can do a "cd" first then run papermill? I assume you need this because your notebook has dependencies? – gogasca Dec 06 '20 at 07:27
  • @gogasca The script reads files from some directories with relative paths. So it will be like "cd /home/jupyter/some_dir \n /opt/conda..."? the '\n' is how I separate the commands inside the script? – Rony Tesler Dec 06 '20 at 17:13
  • https://cloud.google.com/compute/docs/startupscript#providing_startup_script_contents_directly – gogasca Dec 06 '20 at 23:17
  • @gogasca they show examples that can't be done. How can you write code in different lines in a cmd terminal... – Rony Tesler Dec 07 '20 at 15:02
  • The [reference](https://cloud.google.com/compute/docs/startupscript#providing_startup_script_contents_directly) given by @gogasca already shows code in different lines. In the reference you can see --metadata startup-script="your code here; your code at the next line" using ";" acts as new line. – Ricco D Dec 11 '20 at 04:54

0 Answers0