Skip to content

Can't use google-colab #346

Open
Open

Description

@fisakhan

While running the following code, I get an error:

import datetime
import os
import tensorflow as tf
import tensorflow_cloud as tfc
import tensorflow_datasets as tfds
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras.models import Model

if not tfc.remote():
  from google.colab import files

  key_upload = files.upload()
  key_path = list(key_upload.keys())[0]
  os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = key_path
  os.system(f"gcloud auth activate-service-account --key-file {key_path}")

Details of the error:

$ python3 dogs_classification.py 
2021-06-28 12:17:54.852448: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcudart.so.11.0
/home/t/.virtualenvs/tf_cloud/lib/python3.6/site-packages/IPython/utils/traitlets.py:5: UserWarning: IPython.utils.traitlets has moved to a top-level traitlets package.
  warn("IPython.utils.traitlets has moved to a top-level traitlets package.")
<IPython.core.display.HTML object>
Traceback (most recent call last):
  File "dogs_classification.py", line 24, in <module>
    key_upload = files.upload()
  File "/home/t/.virtualenvs/tf_cloud/lib/python3.6/site-packages/google/colab/files.py", line 64, in upload
    input_id=input_id, output_id=output_id))
  File "/home/t/.virtualenvs/tf_cloud/lib/python3.6/site-packages/google/colab/output/_js.py", line 35, in eval_js
    kernel = _ipython.get_kernel()
  File "/home/t/.virtualenvs/tf_cloud/lib/python3.6/site-packages/google/colab/_ipython.py", line 28, in get_kernel
    return get_ipython().kernel
AttributeError: 'InteractiveShell' object has no attribute 'kernel'

I copied the above code from cloud/src/python/tensorflow_cloud/core/tests/examples/dogs_classification.ipynb, and want to run it from dogs_classification.py on my computer.

google-auth-1.32.0
google-colab==1.0.0
tensorflow==2.5.0
tensorflow-cloud==0.1.16

Activity

  1. eddydecena commented on Jul 23, 2021

    @eddydecena

    The library google-colab is not designed to run in a normal Python REPL, which means that you have to run this in an ipython environment like Jupiter notebooks or colab rather than the python interpreter directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions