I am trying to install tensorflow-probability with the following script on a Colab notebook:
!pip3 install -q --user --upgrade tfp-nightly
import tensorflow_probability as tfp
However it doesnt work:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-791d55ac0b39> in <module>()
1 get_ipython().system('pip3 install -q --user --upgrade tfp-nightly')
----> 2 import tensorflow_probability as tfp
ModuleNotFoundError: No module named 'tensorflow_probability'
---------------------------------------------------------------------------
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.
---------------------------------------------------------------------------
Am I doing it correctly? Is it possible to install it on Colab?
Hi Junpeng, that's a great question! The install works for me just running "!pip3 install tfp-nightly" -- I believe the '--user' flag isn't necessary in colab since everything is run in a sandbox by default. However, once installed, I'm seeing the import itself still fail with "ImportError: cannot import name 'seed_stream'" from tensorflow.contrib.distributions.python.ops, which seems to indicate that Colab is preferring its own version of TensorFlow over the nightly package which TFP depends on.
We're certainly interested in making sure TFP works from Colab; we'll engage with the Colab team internally to work this out, and keep you posted. If you or anyone else discovers a workaround in the meantime, feel free to share!
For what it's worth, using a Python2.7 colab seems to work fine for me, running "!pip install tfp-nightly", so that's an (admittedly imperfect) potential workaround.
After some discussion with the Colab team: there's a TF release bug that's causing Python 3 colabs to pull in an outdated version of tf-nightly. When this is fixed, !pip install tfp-nightly will work in Python 3 colabs just as it currently does in Python 2 colabs.
(in the slightly longer term we hope to include TFP in the default colab install, but this should wait until we have a release that depends on stable Tensorflow).
It looks like the Colabs now update with more up-to-date TFP packages. This one can probably be closed.
On Google Colab Python 2 without GPU, I run
!pip install --upgrade tfp-nightly
Then in import tensorflow as tf I got the error in https://github.com/tensorflow/probability/issues/46.
In import tensorflow_probability as tfp, I got
ImportErrorTraceback (most recent call last)
<ipython-input-2-41494c8c96ff> in <module>()
----> 1 import tensorflow_probability as tfp
/usr/local/lib/python2.7/dist-packages/tensorflow_probability/__init__.py in <module>()
19
20 # from tensorflow_probability.google import staging # DisableOnExport
---> 21 from tensorflow_probability.python import * # pylint: disable=wildcard-import
/usr/local/lib/python2.7/dist-packages/tensorflow_probability/python/__init__.py in <module>()
19 from __future__ import print_function
20
---> 21 from tensorflow_probability.python import distributions
22 from tensorflow_probability.python import edward2
23 from tensorflow_probability.python import glm
/usr/local/lib/python2.7/dist-packages/tensorflow_probability/python/distributions/__init__.py in <module>()
20 # pylint: disable=unused-import,line-too-long,g-importing-member
21
---> 22 from tensorflow_probability.python.distributions import bijectors
23
24 from tensorflow_probability.python.distributions.autoregressive import Autoregressive
/usr/local/lib/python2.7/dist-packages/tensorflow_probability/python/distributions/bijectors/__init__.py in <module>()
21 # pylint: disable=unused-import,wildcard-import,line-too-long,g-importing-member
22
---> 23 from tensorflow_probability.python.distributions.bijectors.absolute_value import AbsoluteValue
24 from tensorflow_probability.python.distributions.bijectors.affine import Affine
25 from tensorflow_probability.python.distributions.bijectors.affine_linear_operator import AffineLinearOperator
/usr/local/lib/python2.7/dist-packages/tensorflow_probability/python/distributions/bijectors/absolute_value.py in <module>()
19 from __future__ import print_function
20
---> 21 import tensorflow as tf
22 from tensorflow.python.ops import control_flow_ops
23 from tensorflow.python.ops.distributions import bijector
/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py in <module>()
20
21 # pylint: disable=g-bad-import-order
---> 22 from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
23 from . import app
24 from . import bitwise
/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py in <module>()
47 import numpy as np
48
---> 49 from tensorflow.python import pywrap_tensorflow
50
51 # Protocol buffers
ImportError: cannot import name pywrap_tensorflow
On Google Colab Python 3 without GPU, I do the same thing.
Not sure why, after !pip, I need to "Restart runtime..." before import tensorflow and tensorflow_probability. Then I can successfully import them without the errors appear in Python 2 Colab.
FYI: TFP releases are now installed by default in Colab, so import tensorflow_probability as tfp should 'just work' now without any installation steps.
Closing this issue; feel free to reopen if you run into problems.
Most helpful comment
Hi Junpeng, that's a great question! The install works for me just running "!pip3 install tfp-nightly" -- I believe the '--user' flag isn't necessary in colab since everything is run in a sandbox by default. However, once installed, I'm seeing the import itself still fail with "ImportError: cannot import name 'seed_stream'" from tensorflow.contrib.distributions.python.ops, which seems to indicate that Colab is preferring its own version of TensorFlow over the nightly package which TFP depends on.
We're certainly interested in making sure TFP works from Colab; we'll engage with the Colab team internally to work this out, and keep you posted. If you or anyone else discovers a workaround in the meantime, feel free to share!