重新加载tensorflow模块

时间:2020-04-01 16:57:29

标签: tensorflow tensorflow2.x

在预装有tensorflow-gpu==1.13.1的生产系统中,如果我需要运行tensorflow-gpu==2.1.0,则只能安装并重新加载该库,而无需重新启动系统,但是重新加载tensorflow库给我一个错误,如何我应该解决吗?

要在客户端计算机上重现该问题,

1.First

pip install tensorflow-gpu==1.13.1

2。然后运行以下代码

import tensorflow
print(tensorflow.__version__) 

它将打印

1.13.1

3。现在运行

pip install tensorflow-gpu==2.1.0 

4。如果运行以下代码(我在生产系统上运行以重新加载模块)

import tensorflow
from importlib import reload
tensorflow=reload(tensorflow)
print(tensorflow.__version__) 

您将收到reload引发的以下错误,我该如何解决?

Traceback (most recent call last):
  File "/home/user/anaconda3/envs/tf1/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3326, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-9-453567e02c5c>", line 3, in <module>
    tensorflow=reload(tensorflow)
  File "/home/user/anaconda3/envs/tf1/lib/python3.7/importlib/__init__.py", line 169, in reload
    _bootstrap._exec(spec, module)
  File "<frozen importlib._bootstrap>", line 630, in _exec
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/user/anaconda3/envs/tf1/lib/python3.7/site-packages/tensorflow/__init__.py", line 101, in <module>
    from tensorflow_core import *
  File "/home/user/anaconda3/envs/tf1/lib/python3.7/site-packages/tensorflow_core/__init__.py", line 40, in <module>
    from tensorflow.python.tools import module_util as _module_util
ImportError: cannot import name 'module_util' from 'tensorflow.python.tools' (/home/user/anaconda3/envs/tf1/lib/python3.7/site-packages/tensorflow/python/tools/__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/anaconda3/envs/tf1/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 2040, in showtraceback
    stb = value._render_traceback_()
AttributeError: 'ImportError' object has no attribute '_render_traceback_'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/anaconda3/envs/tf1/lib/python3.7/site-packages/IPython/core/ultratb.py", line 1101, in get_records
    return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
  File "/home/user/anaconda3/envs/tf1/lib/python3.7/site-packages/IPython/core/ultratb.py", line 319, in wrapped
    return f(*args, **kwargs)
  File "/home/user/anaconda3/envs/tf1/lib/python3.7/site-packages/IPython/core/ultratb.py", line 353, in _fixed_getinnerframes
    records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
  File "/home/user/anaconda3/envs/tf1/lib/python3.7/inspect.py", line 1502, in getinnerframes
    frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
  File "/home/user/anaconda3/envs/tf1/lib/python3.7/inspect.py", line 1460, in getframeinfo
    filename = getsourcefile(frame) or getfile(frame)
  File "/home/user/anaconda3/envs/tf1/lib/python3.7/inspect.py", line 696, in getsourcefile
    if getattr(getmodule(object, filename), '__loader__', None) is not None:
  File "/home/user/anaconda3/envs/tf1/lib/python3.7/inspect.py", line 733, in getmodule
    if ismodule(module) and hasattr(module, '__file__'):
  File "/home/user/anaconda3/envs/tf1/lib/python3.7/site-packages/tensorflow/__init__.py", line 50, in __getattr__
    module = self._load()
  File "/home/user/anaconda3/envs/tf1/lib/python3.7/site-packages/tensorflow/__init__.py", line 44, in _load
    module = _importlib.import_module(self.__name__)
  File "/home/user/anaconda3/envs/tf1/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/user/anaconda3/envs/tf1/lib/python3.7/site-packages/tensorflow_core/__init__.py", line 40, in <module>
    from tensorflow.python.tools import module_util as _module_util
ImportError: cannot import name 'module_util' from 'tensorflow.python.tools' (/home/user/anaconda3/envs/tf1/lib/python3.7/site-packages/tensorflow/python/tools/__init__.py)

0 个答案:

没有答案