Dhruv Pandey
Dhruv Pandey

Reputation: 514

Error while importing load_model from keras.model

I am trying to import my keras model which I have saved as .h5 file. But the very first line of my import gives me error. This is the line which gives error

from keras.models import load_model

I checked all the dependencies and that is ok. I have Keras 2.2.4. Error that I am getting:

Using TensorFlow backend.
    Traceback (most recent call last):
      File "drive1.py", line 1, in <module>
        from keras.models import load_model
      File "E:\python3.6.6\lib\site-packages\keras\__init__.py", line 3, in <module>
        from . import utils
      File "E:\python3.6.6\lib\site-packages\keras\utils\__init__.py", line 6, in <module>
        from . import conv_utils
      File "E:\python3.6.6\lib\site-packages\keras\utils\conv_utils.py", line 9, in <module>
        from .. import backend as K
      File "E:\python3.6.6\lib\site-packages\keras\backend\__init__.py", line 89, in <module>
        from .tensorflow_backend import *
      File "E:\python3.6.6\lib\site-packages\keras\backend\tensorflow_backend.py", line 5, in <module>
        import tensorflow as tf
      File "C:\Users\Dhruv\AppData\Roaming\Python\Python36\site-packages\tensorflow\__init__.py", line 24, in <module>
        from tensorflow.python import *  # pylint: disable=redefined-builtin
      File "C:\Users\Dhruv\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\__init__.py", line 52, in <module>
        from tensorflow.core.framework.graph_pb2 import *
      File "C:\Users\Dhruv\AppData\Roaming\Python\Python36\site-packages\tensorflow\core\framework\graph_pb2.py", line 6, in <module>
        from google.protobuf import descriptor as _descriptor
      File "E:\python3.6.6\lib\site-packages\google\protobuf\__init__.py", line 37, in <module>
        __import__('pkg_resources').declare_namespace(__name__)
      File "E:\python3.6.6\lib\site-packages\pkg_resources.py", line 1479, in <module>
        register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
    AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'

I feel like there is some package versions mismatch but not sure what should I check further. I am using pip for installing packages.

Upvotes: 0

Views: 2579

Answers (1)

Dhruv Pandey
Dhruv Pandey

Reputation: 514

Finally from some reference I found that there was some version mismatch between my python and pip. Actually I was should have focused on following error message:

 __import__('pkg_resources').declare_namespace(__name__)

And the thing which helped was

python -m ensurepip --upgrade

Upvotes: 1

Related Questions