携手创造,一起成长!这是我参与「日新方案 8 月更文应战」的第2天,点击检查活动概况


环境阐明:


  • NVIDIA Xavier NX 开发板
  • 装置tensorflow==2.3.0

1 问题阐明

1、装置显现现已成功装置了tensorflow

NVIDIA Jetson Xavier NX上导入tensorflow报错:AttributeError: module ‘wrapt‘ has no att

2、导入tensorflow的时候报错:AttributeError: module 'wrapt' has no attribute 'ObjectProxy'

>>> import tensorflow
2020-10-23 14:09:05.184865: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/zhihui/.local/lib/python3.6/site-packages/tensorflow/__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "/home/zhihui/.local/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 45, in <module>
    from tensorflow.python import data
  File "/home/zhihui/.local/lib/python3.6/site-packages/tensorflow/python/data/__init__.py", line 25, in <module>
    from tensorflow.python.data import experimental
  File "/home/zhihui/.local/lib/python3.6/site-packages/tensorflow/python/data/experimental/__init__.py", line 96, in <module>
    from tensorflow.python.data.experimental import service
  File "/home/zhihui/.local/lib/python3.6/site-packages/tensorflow/python/data/experimental/service/__init__.py", line 21, in <module>
    from tensorflow.python.data.experimental.ops.data_service_ops import distribute
  File "/home/zhihui/.local/lib/python3.6/site-packages/tensorflow/python/data/experimental/ops/data_service_ops.py", line 25, in <module>
    from tensorflow.python.data.experimental.ops import compression_ops
  File "/home/zhihui/.local/lib/python3.6/site-packages/tensorflow/python/data/experimental/ops/compression_ops.py", line 20, in <module>
    from tensorflow.python.data.util import structure
  File "/home/zhihui/.local/lib/python3.6/site-packages/tensorflow/python/data/util/structure.py", line 26, in <module>
    from tensorflow.python.data.util import nest
  File "/home/zhihui/.local/lib/python3.6/site-packages/tensorflow/python/data/util/nest.py", line 41, in <module>
    from tensorflow.python.framework import sparse_tensor as _sparse_tensor
  File "/home/zhihui/.local/lib/python3.6/site-packages/tensorflow/python/framework/sparse_tensor.py", line 28, in <module>
    from tensorflow.python.framework import composite_tensor
  File "/home/zhihui/.local/lib/python3.6/site-packages/tensorflow/python/framework/composite_tensor.py", line 27, in <module>
    from tensorflow.python.util import nest
  File "/home/zhihui/.local/lib/python3.6/site-packages/tensorflow/python/util/nest.py", line 1430, in <module>
    _pywrap_utils.RegisterType("ObjectProxy", _wrapt.ObjectProxy)
AttributeError: module 'wrapt' has no attribute 'ObjectProxy'
>>> 

如果你再次导入:import tensorflow as tf,还有可能会呈现过错:TypeError: Value already registered for Mapping,横竖都是一个问题,请继续看下文吧!

2 解决过错

2.1 找到问题的原因

遇到问题,首要是谷歌、百度,可是结果是没有人遇到这种问题,因而我也就不知道问题该怎么解决!

这时候只能从问题的本源寻觅问题原因,才干找到解决问题的方法,首要定位到问题呈现的代码:/home/zhihui/.local/lib/python3.6/site-packages/tensorflow/python/util/nest.py,所以就到这个文件中去找_wrapt.ObjectProxy,然后通过代码定位到wrapt是一个python的库包

nest.py代码中有导入:

import wrapt as _wrapt

因而我想到这可能是wrapt版别的问题导致的部分特点现已不存在了

1、检查Jetson Xavier NX上装置的wrapt的版别,结果是:1.12.1

zhihui@zhihui-desktop:~$ pip3 show wrapt
Name: wrapt
Version: 1.12.1
Summary: Module for decorators, wrappers and monkey patching.
Home-page: https://github.com/GrahamDumpleton/wrapt
Author: Graham Dumpleton
Author-email: Graham.Dumpleton@gmail.com
License: BSD
Location: /home/zhihui/.local/lib/python3.6/site-packages
Requires: 
Required-by: tensorflow
zhihui@zhihui-desktop:~$ 

2、检查我个人PC上装置wrapt的版别,结果是:1.11.1

C:\Users\93176>pip show wrapt
Name: wrapt
Version: 1.11.1
Summary: Module for decorators, wrappers and monkey patching.
Home-page: https://github.com/GrahamDumpleton/wrapt
Author: Graham Dumpleton
Author-email: Graham.Dumpleton@gmail.com
License: BSD
Location: c:\programdata\anaconda3\lib\site-packages
Requires:
Required-by: -ensorflow-gpu, tensorflow-gpu, astroid
C:\Users\93176>python
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import wrapt as _wrapt
>>> _wrapt.ObjectProxy
<class 'ObjectProxy'>
>>>

因而确定是wrapt版别的问题

2.2 终究过错的解决方法

1、降低wrapt的版别到1.11.1

pip3 install wrapt==1.11.1

2、再次在NVIDIA Jetson Xavier NX导入tensorflow

```python
zhihui@zhihui-desktop:~$ python
Python 3.6.9 (default, Jul 17 2020, 12:50:27) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2020-10-23 14:43:46.641605: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.2
>>> 

并且用:tf.test.is_gpu_available() 回来的也是True,即GPU可用!