4

I was using Google Colab mounted with Google Drive to run some demos. But I got a problem that once that I modified the .py files in my Google Drive, I use !google-drive-ocamlfuse -cc to empty the cache to see the changes. Now I could see that the files in Google Colab machine are already changed, but the results coming out of the runtime just stick to the old versions. As shown below, the result is still 0 instead of 1.

Code before:

def a():
  return 0

Code after:

def a():
  return 1

Questions:

  • How could I fix the problem to make my code effective?
  • How could I see the changes corresponding to my code?
Nimantha
  • 6,405
  • 6
  • 28
  • 69
  • Hi, how did you solve this ? I am facing the same issue. code changes I make in drive are not reflected in colab notebook – Gauranga Jan 25 '21 at 00:28
  • have you checked https://stackoverflow.com/questions/53358250/google-colaboratory-how-to-refresh-google-drive? – Jumboman Feb 17 '21 at 13:44

2 Answers2

1

I used below steps to solve the above problem.

Step 1:

import shutil
shutil.rmtree('__pycache__')

Step 2:

import importlib
import PYTHON_FILE_NAME
importlib.reload(PYTHON_FILE_NAME)

from PYTHON_FILE_NAME import xyz
Sudhanshu
  • 11
  • 1
0

Two steps.

  1. Installed dependencies need to be editable. pip install -e ...

  2. Auto-reload must be set. load_ext autoreload. You may need to specify an autoreload time.

If that doesn’t help, refer to Google-Colaboratory - How to Refresh google-drive? (Thank you jumboman)

Dharman
  • 30,962
  • 25
  • 85
  • 135
A103
  • 1