首页 > 解决方案 > 导入张量流库错误

问题描述

调试后发现下面奇怪的错误

程序:(仅1行)import tensorflow as tf

当我第一次运行上述代码时,我收到以下警告: \AppData\Local\Continuum\anaconda3\lib\site-packages\h5py__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from floatto np.floatingis deprecated。将来,它将被视为np.float64 == np.dtype(float).type. 从 ._conv 导入 register_converters 作为 _register_converters

=>来自网络,这只是一个警告,可以忽略它(我猜)

当我重新运行相同的代码时,出现以下错误

文件“C:\Users\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py”,第 710 行,运行文件 execfile(文件名,命名空间)

文件“C:\Users\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py”,第 101 行,在 execfile exec(compile(f.read(), filename, ' exec'), 命名空间)

文件“H:/Python/Test/Test.py”,第 15 行,在 import tensorflow as tf 中

文件“C:\Users\AppData\Roaming\Python\Python36\site-packages\tensorflow__init__.py”,第 24 行,在 from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import

文件“C:\Users\AppData\Roaming\Python\Python36\site-packages\tensorflow\python__init__.py”,第 121 行,来自 tensorflow.python.platform 导入测试

文件“C:\Users\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\platform\test.py”,第 65 行,在 tf_export('test.mock')(mock)

文件“C:\Users\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\util\tf_export.py”,第 96 行,调用中 (undecorated_func.name , undecorated_func._tf_api_names))

SymbolAlreadyExposedError:符号 unittest.mock 已公开为 ('test.mock',)。

现在我需要重新启动内核才能运行整个源代码。任何想法 ?

谢谢

标签: tensorflowimport

解决方案


我尝试了这种方式并且它起作用了(进一步执行不需要更多的内核重启):

test.py1/从此链接打开文件:

“C:\Users\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\platform\test.py”

2/ 注释第 65 行:#tf_export('test.mock')(mock)


推荐阅读