Import error
See original GitHub issueI created a fresh conda environment with python 3.7.4 and installed tf2 and sonnet2 with:
$ pip install "tensorflow-gpu>=2.0.0rc0" --pre
$ pip install "dm-sonnet>=2.0.0b0" --pre
However, when I try to import sonnet I get the following error:
Python 3.7.4 (default, Aug 13 2019, 20:35:49)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> import sonnet as snt
Traceback (most recent call last):
File "/anaconda3/envs/sonnet/lib/python3.7/site-packages/tensorflow_core/python/autograph/impl/api.py", line 614, in to_graph
return conversion.convert(entity, program_ctx)
File "/anaconda3/envs/sonnet/lib/python3.7/site-packages/tensorflow_core/python/autograph/impl/conversion.py", line 322, in convert
free_nonglobal_var_names)
File "/anaconda3/envs/sonnet/lib/python3.7/site-packages/tensorflow_core/python/autograph/impl/conversion.py", line 240, in _convert_with_cache
entity, program_ctx)
File "/anaconda3/envs/sonnet/lib/python3.7/site-packages/tensorflow_core/python/autograph/impl/conversion.py", line 469, in convert_entity_to_ast
nodes, name, entity_info = convert_func_to_ast(o, program_ctx)
File "/anaconda3/envs/sonnet/lib/python3.7/site-packages/tensorflow_core/python/autograph/impl/conversion.py", line 669, in convert_func_to_ast
node = node_to_graph(node, context)
File "/anaconda3/envs/sonnet/lib/python3.7/site-packages/tensorflow_core/python/autograph/impl/conversion.py", line 699, in node_to_graph
node = converter.apply_(node, context, function_scopes)
File "/anaconda3/envs/sonnet/lib/python3.7/site-packages/tensorflow_core/python/autograph/core/converter.py", line 409, in apply_
node = converter_module.transform(node, context)
File "/anaconda3/envs/sonnet/lib/python3.7/site-packages/tensorflow_core/python/autograph/converters/function_scopes.py", line 120, in transform
return FunctionBodyTransformer(ctx).visit(node)
File "/anaconda3/envs/sonnet/lib/python3.7/site-packages/tensorflow_core/python/autograph/core/converter.py", line 346, in visit
return super(Base, self).visit(node)
File "/anaconda3/envs/sonnet/lib/python3.7/site-packages/tensorflow_core/python/autograph/pyct/transformer.py", line 480, in visit
result = super(Base, self).visit(node)
File "/anaconda3/envs/sonnet/lib/python3.7/ast.py", line 262, in visit
return visitor(node)
File "/anaconda3/envs/sonnet/lib/python3.7/site-packages/tensorflow_core/python/autograph/converters/function_scopes.py", line 87, in visit_FunctionDef
node = self.generic_visit(node)
File "/anaconda3/envs/sonnet/lib/python3.7/ast.py", line 317, in generic_visit
value = self.visit(value)
File "/anaconda3/envs/sonnet/lib/python3.7/site-packages/tensorflow_core/python/autograph/core/converter.py", line 346, in visit
return super(Base, self).visit(node)
File "/anaconda3/envs/sonnet/lib/python3.7/site-packages/tensorflow_core/python/autograph/pyct/transformer.py", line 480, in visit
result = super(Base, self).visit(node)
File "/anaconda3/envs/sonnet/lib/python3.7/ast.py", line 262, in visit
return visitor(node)
File "/anaconda3/envs/sonnet/lib/python3.7/site-packages/tensorflow_core/python/autograph/converters/function_scopes.py", line 44, in visit_Return
value=node.value)
File "/anaconda3/envs/sonnet/lib/python3.7/site-packages/tensorflow_core/python/autograph/pyct/templates.py", line 261, in replace
replacements[k] = _convert_to_ast(replacements[k])
File "/anaconda3/envs/sonnet/lib/python3.7/site-packages/tensorflow_core/python/autograph/pyct/templates.py", line 223, in _convert_to_ast
return gast.Name(id=n, ctx=None, annotation=None)
File "/anaconda3/envs/sonnet/lib/python3.7/site-packages/gast/gast.py", line 19, in create_node
format(Name, nbparam, len(Fields))
AssertionError: Bad argument number for Name: 3, expecting 4
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/anaconda3/envs/sonnet/lib/python3.7/site-packages/sonnet/__init__.py", line 25, in <module>
from sonnet import nets
File "/anaconda3/envs/sonnet/lib/python3.7/site-packages/sonnet/nets.py", line 22, in <module>
from sonnet.src.nets.cifar10_convnet import Cifar10ConvNet
File "/anaconda3/envs/sonnet/lib/python3.7/site-packages/sonnet/src/nets/cifar10_convnet.py", line 22, in <module>
from sonnet.src import batch_norm
File "/anaconda3/envs/sonnet/lib/python3.7/site-packages/sonnet/src/batch_norm.py", line 30, in <module>
class BaseBatchNorm(base.Module):
File "/anaconda3/envs/sonnet/lib/python3.7/site-packages/sonnet/src/batch_norm.py", line 126, in BaseBatchNorm
scale=None, offset=None):
File "/anaconda3/envs/sonnet/lib/python3.7/site-packages/sonnet/src/utils.py", line 172, in smart_autograph
f_autograph = tf.autograph.to_graph(f)
File "/anaconda3/envs/sonnet/lib/python3.7/site-packages/tensorflow_core/python/autograph/impl/api.py", line 618, in to_graph
entity, e.__class__.__name__, str(e)))
tensorflow.python.autograph.impl.api.ConversionError: converting <function BaseBatchNorm.__call__ at 0x7fb3de0db5f0>: AssertionError: Bad argument number for Name: 3, expecting 4
Issue Analytics
- State:
- Created 4 years ago
- Comments:6
Top Results From Across the Web
How to Fix ImportError: Cannot Import Name in Python - Rollbar
The Python ImportError: cannot import name error occurs when an imported class is not accessible or is in a circular dependency.
Read more >Python Import Error (ModuleNotFoundError) - Finxter
Python's ImportError ( ModuleNotFoundError ) indicates that you tried to import a module that Python doesn't find. It can usually be eliminated by...
Read more >Python Exception Handling: ImportError and ... - Airbrake Blog
The ImportError is raised when an import statement has trouble successfully importing the specified module. Typically, such a problem is due to ...
Read more >import error: 'No module named' *does* exist - python
I set the PYTHONPATH to '.' and that solved it for me. export PYTHONPATH='.' For a one-liner you could as easily do: PYTHONPATH='....
Read more >Easiest way to Fix importerror in python ( All in One )
There are two root causes for importerror in python. The First is absence of respective python module and second is incorrect path configuration....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey @ignacio-rocco this looks like a TensorFlow issue with the
gast>0.3.0
. You can work around it for now by downgrading that dependency:I’ll follow up with the autograph team in TensorFlow to see how they recommend fixing. Thanks for the heads up!
On TensorFlow 2.2 or higher, the gast bug has been fixed and gast 0.3+ would be required.