I've installed tensorflow and keras in a virtual environment, but when I try to run from tensorflow.keras.models import load_model I get the following error:
from tensorflow.python.framework.constant_op import constant
ImportError: cannot import name 'constant' from partially initialized module 'tensorflow.python.framework.constant_op' (most likely due to a circular import) (/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/lib/python3.8/site-packages/tensorflow/python/framework/constant_op.py)
I'm running tensorflow version 2.4.0 and Keras 2.4.3 and python 3.8.7
I've uninstalled and reinstalled both tensorflow and keras, but still no chance! Any idea how I can find what's causing this issue?
P.S. This is the full error message:
Traceback (most recent call last):
File "code.py", line 4, in <module>
from tensorflow.keras.models import load_model
File "/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/lib/python3.8/site-packages/tensorflow/__init__.py", line 41, in <module>
from tensorflow.python.tools import module_util as _module_util
File "/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/lib/python3.8/site-packages/tensorflow/python/__init__.py", line 46, in <module>
from tensorflow.python import data
File "/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/lib/python3.8/site-packages/tensorflow/python/data/__init__.py", line 25, in <module>
from tensorflow.python.data import experimental
File "/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/lib/python3.8/site-packages/tensorflow/python/data/experimental/__init__.py", line 96, in <module>
from tensorflow.python.data.experimental import service
File "/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/lib/python3.8/site-packages/tensorflow/python/data/experimental/service/__init__.py", line 140, in <module>
from tensorflow.python.data.experimental.ops.data_service_ops import distribute
File "/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/lib/python3.8/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 "/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/lib/python3.8/site-packages/tensorflow/python/data/experimental/ops/compression_ops.py", line 20, in <module>
from tensorflow.python.data.util import structure
File "/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/lib/python3.8/site-packages/tensorflow/python/data/util/structure.py", line 26, in <module>
from tensorflow.python.data.util import nest
File "/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/lib/python3.8/site-packages/tensorflow/python/data/util/nest.py", line 41, in <module>
from tensorflow.python.framework import sparse_tensor as _sparse_tensor
File "/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/lib/python3.8/site-packages/tensorflow/python/framework/sparse_tensor.py", line 29, in <module>
from tensorflow.python.framework import constant_op
File "/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/lib/python3.8/site-packages/tensorflow/python/framework/constant_op.py", line 29, in <module>
from tensorflow.python.eager import execute
File "/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/lib/python3.8/site-packages/tensorflow/python/eager/execute.py", line 28, in <module>
from tensorflow.python.framework import ops
File "/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/lib/python3.8/site-packages/tensorflow/python/framework/ops.py", line 63, in <module>
from tensorflow.python.platform import app
File "/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/lib/python3.8/site-packages/tensorflow/python/platform/app.py", line 23, in <module>
from absl.app import run as _run
File "/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/lib/python3.8/site-packages/absl/app.py", line 35, in <module>
import pdb
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/pdb.py", line 77, in <module>
import code
File "/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/code.py", line 4, in <module>
from tensorflow.keras.models import load_model
File "/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/lib/python3.8/site-packages/tensorflow/keras/__init__.py", line 14, in <module>
from . import activations
File "/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/lib/python3.8/site-packages/tensorflow/keras/activations/__init__.py", line 10, in <module>
from tensorflow.python.keras.activations import deserialize
File "/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/lib/python3.8/site-packages/tensorflow/python/keras/__init__.py", line 27, in <module>
from tensorflow.python.keras import models
File "/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/lib/python3.8/site-packages/tensorflow/python/keras/models.py", line 23, in <module>
from tensorflow.python.keras import backend as K
File "/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/lib/python3.8/site-packages/tensorflow/python/keras/backend.py", line 37, in <module>
from tensorflow.python.client import session as session_module
File "/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/lib/python3.8/site-packages/tensorflow/python/client/session.py", line 40, in <module>
from tensorflow.python.ops import session_ops
File "/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/lib/python3.8/site-packages/tensorflow/python/ops/session_ops.py", line 30, in <module>
from tensorflow.python.ops import array_ops
File "/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/lib/python3.8/site-packages/tensorflow/python/ops/array_ops.py", line 35, in <module>
from tensorflow.python.framework.constant_op import constant
ImportError: cannot import name 'constant' from partially initialized module 'tensorflow.python.framework.constant_op' (most likely due to a circular import) (/Users/Gabriel/Development/Projects/Keras-FaceNet_demo/lib/python3.8/site-packages/tensorflow/python/framework/constant_op.py)
From Comments
code.py is already defined in python packages. Hence after renaming
code.pyfile to something other name has resolved the problem (paraphrased from Macattack).
From Comments
code.py is already defined in python packages. Hence after renaming
code.pyfile to something other name has resolved the problem (paraphrased from Macattack).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With