Running lesson 8 in Google colab

Hey guys,

I had some issue with running the “export” parts of the lesson using Google colab. After I figure this out, there is nothing complicated about it, but I’ll add it here anyway to save you some time.
Assuming the google drive is already mounted to colab, this is what you need to do:

  1. Download notebook2script.py from the course github and upload it to Google drive’s “Colab Notebooks” folder (make sure to download the “Raw” code and not copy/paste it)

  2. Run the following code in colab:
    !pip install fire
    cd gdrive/My\ Drive/Colab\ Notebooks
    !chmod 700 notebook2script.py
    !mkdir exp

  3. Make sure that the file to export name is the same as the notebook’s name

19 Likes

Hello Kagan. Thx for helping me out. I managed to get the export working. So now my exported files are in ‘content/drive/My Drive/Colab Notebooks/exp’

However I have issues with the import. I run the import cell when my current directory is
‘/content/drive/My Drive/Colab Notebooks’. Unfortunately, I get this error

ModuleNotFoundError: No module named 'exp.nb_01'

Did you get this working as well?

Hey Martijn,

The import should work on it’s own. I just checked this again, and there is nothing you need to do besides mounting google drive and changing the working directory to content/drive/My Drive/Colab Notebooks
Please double check that nb_01 exists inside the exp folder.

2 Likes

You are right. Don’t know what I did wrong before, but now it’s working smoothly.

Thx a lot.

THANK YOU!! for some reason, this was not a prob for nb_1 but the 2nd nb would NOT export. I am using CrestleAI and I just removed the 2nd line of code. Thank you so much!

Thanks for sharing this part of code. It was really helpful.

1 Like

hi david
do we need to manually upload all the files into the exp folder after mount ?

i got the work around…
I created exp folder under default path of colab which .content/. copied all the .py files to it… there after was able to run all nbs without issues

I’m not sure I understand the issue you had correctly, but you don’t have to upload the files manually.
As part of the steps I described you should create an exp folder in your google drive, after this, if you run all the notebooks in the right order, you will create all of the nb_xx.py notebooks by yourself.
The exp folder is in your google drive, so if for whatever reason you want to upload the nb_xx.py notebooks into it, you defiantly can do it. If you chose to do it this way though, make sure to create an empty file named __init__.py inside of exp folder.
I’m not sure why it works without the __init.py__ for created files but doesn’t work without it for uploaded files.

@martijnd could you share with me, how you get this line to work ? Followed the instructions above

I suspect you changed the present work directory here simply to where the notebook is, but I don’t quite know how to do that in swift notebooks yet.

Only dirty workaround I can do is upload a version to root and reference it
with …/ : notebookToScript(fname: Path.cwd/"…/00_load_data.ipynb")

Here’s a Jupyter notebook to guide you through the steps needed to run the course notebooks in Google Colab: Colab setup for Part 2 2019