ImportError: dlopen(…): Library not loaded: @rpath/_pywrap_tensorflow_internal.so

Question:

I am a beginner at machine learning. I try to use LSTM algorism but when I write

from keras.models import Sequential

it shows error as below:

ImportError: dlopen(/Users/wangzifan/opt/anaconda3/lib/python3.9/site-packages/tensorflow/python/_pywrap_tfe.so, 2): Library not loaded: @rpath/_pywrap_tensorflow_internal.so
  Referenced from: /Users/wangzifan/opt/anaconda3/lib/python3.9/site-packages/tensorflow/python/_pywrap_tfe.so
  Reason: image not found

How can I fix this? Thank you so much!

full error message:

Traceback (most recent call last):
  File "/Users/wangzifan/Desktop/machine/LSTM.py", line 39, in <module>
    from keras.models import Sequential
  File "/Users/wangzifan/opt/anaconda3/lib/python3.9/site-packages/keras/__init__.py", line 21, in <module>
    from tensorflow.python import tf2
  File "/Users/wangzifan/opt/anaconda3/lib/python3.9/site-packages/tensorflow/__init__.py", line 37, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "/Users/wangzifan/opt/anaconda3/lib/python3.9/site-packages/tensorflow/python/__init__.py", line 37, in <module>
    from tensorflow.python.eager import context
  File "/Users/wangzifan/opt/anaconda3/lib/python3.9/site-packages/tensorflow/python/eager/context.py", line 33, in <module>
    from tensorflow.python import pywrap_tfe
  File "/Users/wangzifan/opt/anaconda3/lib/python3.9/site-packages/tensorflow/python/pywrap_tfe.py", line 25, in <module>
    from tensorflow.python._pywrap_tfe import *
ImportError: dlopen(/Users/wangzifan/opt/anaconda3/lib/python3.9/site-packages/tensorflow/python/_pywrap_tfe.so, 2): Library not loaded: @rpath/_pywrap_tensorflow_internal.so
  Referenced from: /Users/wangzifan/opt/anaconda3/lib/python3.9/site-packages/tensorflow/python/_pywrap_tfe.so
  Reason: image not found

Asked By: Logixxx

||

Answers:

Problem solved. install tensorflow again with

sudo pip3 install tensorflow

and change the import to

from tensorflow.python.keras.models import Sequential
Answered By: Logixxx

I solve this annoying issue with

pip3 install --upgrade tensorflow --user

My environment is

Python 3.7.9
conda 22.9.0
Answered By: Roman
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.