Search code examples
pythontensorflowmachine-learningcomputer-visiongoogle-colaboratory

How do I install a previous version of Tensorflow on Google Colab?


I uninstalled the pre-installed version of Tensorflow on Google Colab by using !pip uninstall tensorflow -y and then !pip uninstall tensorflow-gpu -y. Then I installed the version I desired !pip install tensorflow-gpu==1.4.1 which seems to work and it outputs Successfully installed tensorflow-gpu-1.4.1. However, when I run !pip show tensorflow I get WARNING: Package(s) not found: tensorflow.

I've already tried restarting the runtime after installing Tensorflow but that didn't work. I am also running a GPU runtime.

Also, when I run:

import tensorflow as tf print(tf.__version__)

I get the following error:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/pywrap_tensorflow.py in <module>()
     57 
---> 58   from tensorflow.python.pywrap_tensorflow_internal import *
     59   from tensorflow.python.pywrap_tensorflow_internal import __version__

10 frames
ImportError: libcublas.so.8.0: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/pywrap_tensorflow.py in <module>()
     70 for some common reasons and solutions.  Include the entire stack trace
     71 above this error message when asking for help.""" % traceback.format_exc()
---> 72   raise ImportError(msg)
     73 
     74 # pylint: enable=wildcard-import,g-import-not-at-top,unused-import,line-too-long

ImportError: Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "/usr/lib/python3.6/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "/usr/lib/python3.6/imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: libcublas.so.8.0: cannot open shared object file: No such file or directory


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

How could I solve this problem to correctly install Tensorflow 1.4.1? I've already tried restarting the runtime after installing Tensorflow but that didn't work. I am also running a GPU runtime.


Solution

  • Try reinstalling tensorflow with the following commands

    !pip uninstall tensorflow -y
    !pip install  tensorflow==1.14
    

    then restart runtime when asked in colab. You should be able to import the correct version of TensorFlow.

    %tensorflow_version 1.x
    import tensorflow as tf
    print(tf.__version__)
    
    1.14.0