Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name 'docstring' from 'tensorflow_probability.python.util' #37

Closed
nbro opened this issue Oct 14, 2019 · 4 comments

Comments

@nbro
Copy link

nbro commented Oct 14, 2019

I have a virtual environment (with Python 3.7.4) where I installed edward2, tensorflow (2) and tensorflow_probability. When I try to import edward2 with import edward2 as ed, I get the error

ImportError: cannot import name 'docstring' from 'tensorflow_probability.python.util'

Here's the full Traceback

Traceback (most recent call last):
File "/Users/nbro/Desktop/edward_tests/edward_test2.py", line 1, in
import edward2 as ed
File "/Users/nbro/Desktop/edward_tests/venv2/lib/python3.7/site-packages/edward2/init.py", line 32, in
from edward2 import generated_random_variables
File "/Users/nbro/Desktop/edward_tests/venv2/lib/python3.7/site-packages/edward2/generated_random_variables.py", line 26, in
from tensorflow_probability.python.util import docstring as docstring_util
ImportError: cannot import name 'docstring' from 'tensorflow_probability.python.util' (/Users/nbro/Desktop/edward_tests/venv2/lib/python3.7/site-packages/tensorflow_probability/python/util/init.py)

@dustinvtran
Copy link
Member

Are you installing Edward2's development version?

pip install -e "git+https://github.com/google/edward2.git#egg=edward2"

The stable version hasn't been updated yet.

@nbro
Copy link
Author

nbro commented Oct 14, 2019

@dustinvtran No, as I had said above, I was installing edward2 with pip install edward2. I tried to install it with pip install -e "git+https://github.com/google/edward2.git#egg=edward2", but now I get another error ModuleNotFoundError: No module named 'scipy',

Traceback (most recent call last):
  File "/Users/nbro/Desktop/edward_tests/edward_test2.py", line 14, in <module>
    import edward2 as ed
  File "/Users/nbro/Desktop/edward_tests/venv/src/edward2/edward2/__init__.py", line 33, in <module>
    from edward2 import tensorflow
  File "/Users/nbro/Desktop/edward_tests/venv/src/edward2/edward2/tensorflow/__init__.py", line 34, in <module>
    from edward2.tensorflow import layers
  File "/Users/nbro/Desktop/edward_tests/venv/src/edward2/edward2/tensorflow/layers/__init__.py", line 22, in <module>
    from edward2.tensorflow.layers import utils
  File "/Users/nbro/Desktop/edward_tests/venv/src/edward2/edward2/tensorflow/layers/utils.py", line 24, in <module>
    from scipy.optimize import linear_sum_assignment
ModuleNotFoundError: No module named 'scipy'

So I tried to install scipy manually with pip install scipy.

To be specific, I am trying to run this example http://edwardlib.org/tutorials/bayesian-neural-network, which is supposed to run with edward and TensorFlow 1, but I want to run it with edward 2 and TensorFlow 2.

Now, I have another error, but it is related to TensorFlow 2.

tensorflow.python.framework.errors_impl.InvalidArgumentError: cannot compute MatMul as input #1(zero-based) was expected to be a double tensor but is a float tensor [Op:MatMul] name: model/MatMul/

which is apparently due to inconsistent use of types. See https://stackoverflow.com/a/54255819/3924118. So, in the file https://github.com/blei-lab/edward/blob/master/examples/bayesian_nn.py, I changed the function build_toy_dataset to return float32 arrays.

Anyway, after having installed edward2 with pip install -e "git+https://github.com/google/edward2.git#egg=edward2", now PyCharm tells me No module named edward2 at the line import edward2 as ed, even though pip list lists edward2, and no run-time error is thrown, after having launched the script, so I think this problem is only related to PyCharm. In fact, I've just found the solution here https://stackoverflow.com/a/38200233/3924118.

@dustinvtran
Copy link
Member

To be specific, I am trying to run this example http://edwardlib.org/tutorials/bayesian-neural-network, which is supposed to run with edward and TensorFlow 1, but I want to run it with edward 2 and TensorFlow 2.

Edward2 is a separate version number because it's not backwards compatible like that. We're still in the process of updating those examples to an Edward2-like workflow.

but now I get another error ModuleNotFoundError: No module named 'scipy',

That's interesting.. That shouldn't happen. I'll look into it!

edward-bot pushed a commit that referenced this issue Oct 23, 2019
edward-bot pushed a commit that referenced this issue Oct 23, 2019
@atharvakhandve
Copy link

Are you installing Edward2's development version?

pip install -e "git+https://github.com/google/edward2.git#egg=edward2"

The stable version hasn't been updated yet.

I tried installing it with the above command. The installation was succesful but whenever I import it there is an error like "No module named edward2"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants