当前位置:   article > 正文

module 'tensorflow' has no attribute 'keras'

module 'tensorflow' has no attribute 'keras

安装好tensorflowjs后报错

 

   因为自己之前一直是使用tf2.0,而tensorflowjs使用不了2.0,而且记得命名手动删去site-packages下的tensorflow后,安装的tensorflowjs-1.3.2的,而且显示安装是成功了的,因为tensorflowjs-1.3.2依赖的是tensorflow1.15的,但是运行上面代码出了问题,问题实际上是自己配置的pip豆瓣源,所以以前存留了tensorflow2.0的安装文件。

  1. C:\Users\Administrator>python
  2. Python 3.5.2 |Anaconda 4.1.1 (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32
  3. Type "help", "copyright", "credits" or "license" for more information.
  4. >>> import tensorflow
  5. D:\AN\lib\site-packages\numpy\core\__init__.py:29: UserWarning: loaded more than 1 DLL from .libs:
  6. D:\AN\lib\site-packages\numpy\.libs\libopenblas.PYQHXLVVQ7VESDPUVUADXEVJOBGHJPAY.gfortran-win_amd64.dll
  7. D:\AN\lib\site-packages\numpy\.libs\libopenblas.TXA6YQSD3GCQQC22GEQ54J2UDCXDXHWN.gfortran-win_amd64.dll
  8. stacklevel=1)
  9. >>> print(tensorflow.__version__)
  10. 2.0.0
  11. >>> import tensorflowjs
  12. Traceback (most recent call last):
  13. File "<stdin>", line 1, in <module>
  14. File "D:\AN\lib\site-packages\tensorflowjs\__init__.py", line 21, in <module>
  15. from tensorflowjs import converters
  16. File "D:\AN\lib\site-packages\tensorflowjs\converters\__init__.py", line 24, in <module>
  17. from tensorflowjs.converters.tf_saved_model_conversion_v2 import convert_tf_saved_model
  18. File "D:\AN\lib\site-packages\tensorflowjs\converters\tf_saved_model_conversion_v2.py", line 38, in <module>
  19. import tensorflow_hub as hub
  20. File "D:\AN\lib\site-packages\tensorflow_hub\__init__.py", line 53, in <module>
  21. from tensorflow_hub.keras_layer import KerasLayer
  22. File "D:\AN\lib\site-packages\tensorflow_hub\keras_layer.py", line 39, in <module>
  23. class KerasLayer(tf.keras.layers.Layer):
  24. File "C:\Users\Administrator\AppData\Roaming\Python\Python35\site-packages\tensorflow_core\python\util\module_wrapper.py", line 169, in __getattr__
  25. attr = getattr(self._tfmw_wrapped_module, name)
  26. AttributeError: module 'tensorflow' has no attribute 'keras'

我发现根本现在使用的不是1.15而是2.0的,而且连import tensorflowjs都不成功的

解决方式,是在pip安装的文件下,删了tensorflow的所有文件,重新打开即可,一般来说pip源安装好的文件在:

C:\Users\Administrator\AppData\Roaming\Python\Python35\site-packages

现在就能执行成功了

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/225066
推荐阅读
相关标签
  

闽ICP备14008679号