IPython magic-command %notebook does not work when spaces are present in path (Google Colab)

前提是你 提交于 2021-01-29 08:51:05

问题


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?

来源:https://stackoverflow.com/questions/60449515/ipython-magic-command-notebook-does-not-work-when-spaces-are-present-in-path-g

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!