tensorflow: ModuleNotFoundError: No module named 'tensorflow.compat.v2'
Was going through the Jupyter notebook on TFP that was associated with the TF Dev Summit:
Running the line
import tensorflow.compat.v2 as tf
Returns the error:
ModuleNotFoundError: No module named ‘tensorflow.compat.v2’
Running tf.VERSION shows it’s 1.13.
I’m assuming this is related to not having TF 2.0 installed, and only having T 1.13 installed. Is a separate, 2nd installation of TF (2.0) needed to import tensorflow.compat.v2 or can both be installed into the same virtual environment?
Just want to make sure installing both alongside each other won’t break either or both.
You can collect some of this information using our environment capture script You can also obtain the TensorFlow version with python -c “import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)”
b’unknown’ 1.13.1
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 42 (8 by maintainers)
I am having the same error as well
@cpoptic just want to add my observation here, in my understanding
tensorflow-probabilityis not installed along withtensorflow. Could please try with your test script after installingpip install --user --upgrade tensorflow-probabilityHope this will help youI am having the same error.
I have tensorflow 1.4.0 with Cuda 8 and cudnn 7. And I get the following error.
import tensorflow.compat.v1 as tf ImportError: No module named 'tensorflow.compat'After installing
tensorflow-probability, I still get the same error.@MarkDaoust I fixed it by install tf-nightly-gpu.
!pip install -U "tensorflow==2.0"I was facing similar issues but this solved the problem for me. Thanks!
One common way to get stuck in a particular tensorflow version is to have an old version of python or pip.
If you try to install a specific version and it fails then check your python and pip versions.
pip install tensorflowonly gets you the latest version if those are up to date.If your problem is with RASA CORE, in my case, I executed the following commands: pip install -U tensorflow==1.15 pip install -U tensorflow==2.0 pip install -U gast==0.3.3 pip install -U tf-nightly-gpu pip install -U tensorboard==1.15.0 pip install -U tensorflow==1.15
@himanshisyadav upgrade to at least TF 1.14.
Hi Everyone,
When this was published, it required tf-nightly or any of preview releases of tensorflow -2.0. That was the original source of confusion.
The tf.compat.v2 module was added in 1.14. Upgrade to 1.14 , 1.15, or 2.0 and this will work fine.
There is absolutely no way to run it with 1.13, or 1.8, sorry!
I have changed with import tensorflow.compat.v2 as tf v2 to v1 as wll but it not work ModuleNotFoundError: No module named ‘tensorflow.compat’
你的来信已收到,谢谢!
你的来信已收到,谢谢!
is this problem solved? please help I faced the same error.
Yes that works, but the issue is with the tensorflow_probability
AttributeError: module ‘tensorflow.compat’ has no attribute ‘v2’
AttributeError Traceback (most recent call last) <ipython-input-10-6713d3750cfa> in <module> 17 # import tensorflow.compat.v2 as tf 18 import tensorflow.compat.v1 as tf —> 19 import tensorflow_probability as tfp 20 21 tf.enable_v2_behavior()
/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_probability/init.py in <module> 76 77 # from tensorflow_probability.google import staging # DisableOnExport —> 78 from tensorflow_probability.python import * # pylint: disable=wildcard-import 79 from tensorflow_probability.python.version import version 80 # pylint: enable=g-import-not-at-top
/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_probability/python/init.py in <module> 27 from tensorflow_probability.python import mcmc 28 from tensorflow_probability.python import monte_carlo —> 29 from tensorflow_probability.python import optimizer 30 from tensorflow_probability.python import positive_semidefinite_kernels 31 from tensorflow_probability.python import stats
/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_probability/python/optimizer/init.py in <module> 28 from tensorflow_probability.python.optimizer.proximal_hessian_sparse import minimize as proximal_hessian_sparse_minimize 29 from tensorflow_probability.python.optimizer.proximal_hessian_sparse import minimize_one_step as proximal_hessian_sparse_one_step —> 30 from tensorflow_probability.python.optimizer.sgld import StochasticGradientLangevinDynamics 31 from tensorflow_probability.python.optimizer.variational_sgd import VariationalSGD 32
/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow_probability/python/optimizer/sgld.py in <module> 32 33 —> 34 class StochasticGradientLangevinDynamics(tf.compat.v2.optimizers.Optimizer): 35 “”"An optimizer module for stochastic gradient Langevin dynamics. 36
AttributeError: module ‘tensorflow.compat’ has no attribute ‘v2’