pymc4 icon indicating copy to clipboard operation
pymc4 copied to clipboard

import error

Open worasom opened this issue 4 years ago • 3 comments

I installed tensorflow 2.1 and pymc4 on window 10 machine. The packages are install in a new venv environment. I can import tensorflow (with some warning), but when trying to import pymc4 I got this error "AttributeError: module 'tensorflow_core.compat.v2.math' has no attribute 'xlog1py'" I check and found that tensorflow.math.xlog1py throws the same error. Please suggest.

import tensorflow 2020-02-11 09:55:38.474276: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found 2020-02-11 09:55:38.482351: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.

import pymc4 Traceback (most recent call last): File "", line 1, in File "c:\Users\user\pyenv\py36\lib\site-packages\pymc4_init_.py", line 6, in from . import distributions File "c:\Users\user\pyenv\py36\lib\site-packages\pymc4\distributions_init_.py", line 1, in from .continuous import * File "c:\Users\user\pyenv\py36\lib\site-packages\pymc4\distributions\continuous.py", line 4, in from tensorflow_probability import distributions as tfd File "c:\Users\user\pyenv\py36\lib\site-packages\tensorflow_probability_init_.py", line 76, in from tensorflow_probability.python import * # pylint: disable=wildcard-import File "c:\Users\user\pyenv\py36\lib\site-packages\tensorflow_probability\python_init_.py", line 21, in from tensorflow_probability.python import bijectors File "c:\Users\user\pyenv\py36\lib\site-packages\tensorflow_probability\python\bijectors_init_.py", line 23, in from tensorflow_probability.python.bijectors.absolute_value import AbsoluteValue File "c:\Users\user\pyenv\py36\lib\site-packages\tensorflow_probability\python\bijectors\absolute_value.py", line 23, in from tensorflow_probability.python.bijectors import bijector File "c:\Users\user\pyenv\py36\lib\site-packages\tensorflow_probability\python\bijectors\bijector.py", line 33, in from tensorflow_probability.python.internal import distribution_util File "c:\Users\user\pyenv\py36\lib\site-packages\tensorflow_probability\python\internal\distribution_util.py", line 28, in from tensorflow_probability.python.internal import prefer_static File "c:\Users\user\pyenv\py36\lib\site-packages\tensorflow_probability\python\internal\prefer_static.py", line 30, in from tensorflow_probability.python.internal.backend import numpy as nptf File "c:\Users\user\pyenv\py36\lib\site-packages\tensorflow_probability\python\internal\backend\numpy_init_.py", line 22, in from tensorflow_probability.python.internal.backend.numpy import compat File "c:\Users\user\pyenv\py36\lib\site-packages\tensorflow_probability\python\internal\backend\numpy\compat.py", line 24, in from tensorflow_probability.python.internal.backend.numpy import v1 File "c:\Users\user\pyenv\py36\lib\site-packages\tensorflow_probability\python\internal\backend\numpy\v1.py", line 37, in from tensorflow_probability.python.internal.backend.numpy.random_generators import set_seed File "c:\Users\user\pyenv\py36\lib\site-packages\tensorflow_probability\python\internal\backend\numpy\random_generators.py", line 27, in from tensorflow_probability.python.internal.backend.numpy.numpy_math import softmax as _softmax File "c:\Users\user\pyenv\py36\lib\site-packages\tensorflow_probability\python\internal\backend\numpy\numpy_math.py", line 912, in tf.math.xlog1py, AttributeError: module 'tensorflow_core.compat.v2.math' has no attribute 'xlog1py' tensorflow.math.xlog1py Traceback (most recent call last): File "", line 1, in AttributeError: module 'tensorflow_core._api.v2.math' has no attribute 'xlog1py'

worasom avatar Feb 12 '20 17:02 worasom

Just force upgrade your package using: pip install --upgrade --force tensorflow_probability. If it doesn't work reinstalling TensorFlow Probability may help!

tirthasheshpatel avatar Feb 12 '20 18:02 tirthasheshpatel

I tried upgrade and reinstall, but still does not work.

worasom avatar Feb 13 '20 17:02 worasom

@worasom, although it will sound strange, the problem you are seeing is caused because you installed the tensorflow package. I'll explain why.

When we started developing pymc4, we made the package depend on tensorflow-nightly, because we wanted to profit from the latest unreleased v2 features. As pymc4 is still quite fluid and not ready for a beta release we haven't switched to depend on the latest official releases on tensorflow and tensorflow_probability.

You may be asking yourself why does this cause an error? The thing is that from pip's (and setuptools) point of view, tensorflow and tensorflow-nightly are two completely unrelated packages. The problem is that in fact they aren't. They both end up populating the exact same directory in your python's site-package directory. This means that if you try to install both tensorflow and tensorflow-nightly, pip will overwrite things incorrectly and you'll end up with a broken installation. The sequence of things that lead to your error are:

  1. Pip installs tensorflow
  2. Try to pip install pymc4
  3. Pip looks up the pymc4 requirements and finds it needs to install tensorflow-nightly.
  4. Pip installs tensorflow-nightly and breaks the previous tensorflow installation, but pip thinks that everything went great because from its point of view, tensorflow and tensorflow-nightly are completely unrelated packages.
  5. When you try to import pymc4, python fails to import tensorflow and errors out.

How do you fix things? First you'll have to completely uninstall tensorflow. Then you just have to run pip install pymc4 and requirements will be handled automatically.

lucianopaz avatar Feb 14 '20 19:02 lucianopaz