1

In jupyter-lab I can use the magic command %notebook $output_file_path to save the history notebook as a jupyter notebook. When I am working with Google Colab (mounting Google Drive) the path of my notebook folder is something like:

root_path = 'gdrive/My Drive/Colab Notebooks/my_working_folder/'

The problem is that, as I try to save the notebook history, the space between "My" and "Drive" makes the magic command fail

output_file_path = 'gdrive/My Drive/Colab Notebooks/my_working_folder/nb_history.ipynb'
%notebook $output_file_path

with the following error:

UsageError: unrecognized arguments: Drive/Colab Notebooks/my_working_folder/nb_history.ipynb

I tried replacing the spaces with "\" or "\\" or "\ " or "\\ " with no success. I also tried to "embed" the path string into quotes like

output_file_path = '"gdrive/My Drive/Colab Notebooks/my_working_folder/nb_history.ipynb"'

with no success either, getting a different error:

FileNotFoundError: [Errno 2] No such file or directory: '"gdrive/My Drive/Colab Notebooks/my_working_folder/nb_history.ipynb"'

Is there a workaround I can exploit to use the %notebook magic?

Andrea
  • 2,932
  • 11
  • 23
  • 1
    Save it in your current working directory without the path first and then move it using @55597 's answer? You say shell commands work, so `!mv` may work? – Wayne Feb 28 '20 at 17:58
  • 1
    That would do the trick, but I would love to have a more "direct" solution – Andrea Feb 28 '20 at 18:22
  • Same behavior. Maybe a limitation of Python 3.7's IPython? – Sterling Oct 08 '22 at 02:51

0 Answers0