Home > database >  Tensor flow for ML program failing to load the native runtime MacOS Python 3.9.6
Tensor flow for ML program failing to load the native runtime MacOS Python 3.9.6

Time:09-17

When installing tensor flow on MacOS I would receive an error about "An appropriate version not being found". I used this following command to download an older version of tensorflow

pip3 install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.0.0-py3-none-any.whl

Here is the code for the program being written

import json 
import numpy as np 
import tensorflow as tf
import keras 

keras is imported separately because it can't be added from tensor flow 1.

from keras.models import Sequential
from keras.layers import Dense, Embedding, GlobalAveragePooling1D
from keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences
from sklearn.preprocessing import LabelEncoder
with open('intents.json') as file:
    data = json.load(file) #loading json file and extracting data
    
training_sentences = [] #contains training data(sample messages in each intent catagory)
training_labels = []
labels = [] #holds target labels connected to each training data
responses = [] #contains responses

for intent in data['intents']: #iterate over the variable intent in the json file
    for pattern in intent['patterns']: #pattern contained in intent
        training_sentences.append(pattern) #add the user input into a certain tag of dialogue
        training_labels.append(intent['tag']) #adds a new type of tag
    responses.append(intent['responses']) #add a new response
    
    if intent['tag'] not in labels:
        labels.append(intent['tag'])
        
num_classes = len(labels)

print (intent)

And the error received when executed is as follows

(its a very long one)

Traceback (most recent call last):
  File "/Users//Library/Python/3.9/lib/python/site-packages/tensorflow/python/__init__.py", line 61, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/Users//Library/Python/3.9/lib/python/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/Users//Library/Python/3.9/lib/python/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: dlopen(/Users//Library/Python/3.9/lib/python/site-packages/tensorflow/python/_pywrap_tensorflow.so, 0x000A): tried: '/Users//Library/Python/3.9/lib/python/site-packages/tensorflow/python/_pywrap_tensorflow.so' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e)))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users//Documents/VScode/Python/NEA/NEA_AI.PY", line 4, in <module>
    import tensorflow as tf
  File "/Users//Library/Python/3.9/lib/python/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/Users//Library/Python/3.9/lib/python/site-packages/tensorflow/python/__init__.py", line 72, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/Users//Library/Python/3.9/lib/python/site-packages/tensorflow/python/__init__.py", line 61, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/Users//Library/Python/3.9/lib/python/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/Users//Library/Python/3.9/lib/python/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: dlopen(/Users//Library/Python/3.9/lib/python/site-packages/tensorflow/python/_pywrap_tensorflow.so, 0x000A): tried: '/Users//Library/Python/3.9/lib/python/site-packages/tensorflow/python/_pywrap_tensorflow.so' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e)))


Failed to load the native TensorFlow runtime.

See https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#import_error

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.

CodePudding user response:

ImportError: dlopen(/Users//Library/Python/3.9/lib/python/site-packages/tensorflow/python/_pywrap_tensorflow.so, 0x000A): tried: '/Users//Library/Python/3.9/lib/python/site-packages/tensorflow/python/_pywrap_tensorflow.so' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e)))

OK, above error log is straightforward, your are using x86_64 version on a ARM macos. check _pywrap_tenserflow.so

As you can see from above picture, it's a x86_64 dylib.

You can check this github issue, tensorflow wheels for Apple Silicon is still developing:

@rgov thank you for summarizing this issue. On behalf of the Apple and Google teams working on this, we are planning official support for Apple Silicon (Aarch64 based) CPUs, and to streamline GPU support. I'll follow up in this issue when we have more to share.

Also check this Github issue, it contains some promissing workarounds:

python -m pip install tensorflow-macos
python -m pip install tensorflow-metal
  • Related