Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

Cant start tensorflow on M1: mach-o, but wrong architecture #146

Open
white-collar opened this issue Jan 30, 2021 · 18 comments
Open

Cant start tensorflow on M1: mach-o, but wrong architecture #146

white-collar opened this issue Jan 30, 2021 · 18 comments

Comments

@white-collar
Copy link

Hello.
I have followed the manual from this github and started

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/apple/tensorflow_macos/master/scripts/download_and_install.sh)"

It seems to be virtual environment has been created but when I activate it and start importing tensorflow in my script I get the following:

`>>> import tensorflow as tf
Traceback (most recent call last):
File "/Users/a1/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: dlopen(/Users/a1/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): no suitable image found. Did find:
/Users/a1/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture
/Users/a1/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 1, in
File "/Users/a1/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/init.py", line 41, in
from tensorflow.python.tools import module_util as _module_util
File "/Users/a1/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/init.py", line 39, in
from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
File "/Users/a1/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 83, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/Users/a1/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: dlopen(/Users/a1/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): no suitable image found. Did find:
/Users/a1/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture
/Users/a1/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture

Failed to load the native TensorFlow runtime.
`

any hints or advices around this ?

Thank you

@asd3427
Copy link

asd3427 commented Jan 30, 2021

I also encountered this problem

(tensorflow_macos_venv) mike@mikechendeMacBook-Pro pythonProject % python 
Python 3.8.7 (v3.8.7:6503f05dd5, Dec 21 2020, 12:45:15) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
  File "/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 64, in <module>
    from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: dlopen(/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): no suitable image found.  Did find:
        /Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture
        /Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/__init__.py", line 39, in <module>
    from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
  File "/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 83, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 64, in <module>
    from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: dlopen(/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): no suitable image found.  Did find:
        /Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture
        /Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

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

@white-collar white-collar changed the title Cant start tensorflow on M1 Cant start tensorflow on M1: mach-o, but wrong architecture Jan 30, 2021
@ItsSmarti
Copy link

Exactly the same problem here.

@MalteSil
Copy link

I've encountered similar issues. The problem for me was that my venv was running on a different architecture than my base interpreter. Make sure they both don't run on rosetta, u can do that by unchecking "open with rosetta" when you right click and get info on the terminal in the finder.

@asd3427
Copy link

asd3427 commented Jan 31, 2021

I've encountered similar issues. The problem for me was that my venv was running on a different architecture than my base interpreter. Make sure they both don't run on rosetta, u can do that by unchecking "open with rosetta" when you right click and get info on the terminal in the finder.

HMMM i tried this but it seen not work can you give me a simple video teach?

@white-collar
Copy link
Author

I've encountered similar issues. The problem for me was that my venv was running on a different architecture than my base interpreter. Make sure they both don't run on rosetta, u can do that by unchecking "open with rosetta" when you right click and get info on the terminal in the finder.

Can you pls explain with more details ? I start IDLE.app as is, there is no choice use Rosetta2 or no. The same when I do this in jupyter notebook.

@MalteSil
Copy link

U can find the same issue with more explanation here

@asd3427
Copy link

asd3427 commented Feb 1, 2021

你可以在这里找到更多解释的相同问题

i follow that post to do same things it still not work.......

mike@mikechendeMacBook-Pro ~ % uname -m
arm64
mike@mikechendeMacBook-Pro ~ % suorce tensorflow_macos_venv/bin/activate
zsh: command not found: suorce
mike@mikechendeMacBook-Pro ~ % soyrce tensorflow_macos_venv/bin/activate
zsh: command not found: soyrce
mike@mikechendeMacBook-Pro ~ % source tensorflow_macos_venv/bin/activate
(tensorflow_macos_venv) mike@mikechendeMacBook-Pro ~ % uname -m
arm64
(tensorflow_macos_venv) mike@mikechendeMacBook-Pro ~ % python
Python 3.8.7 (default, Dec 30 2020, 02:09:32)
[Clang 12.0.0 (clang-1200.0.32.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
  File "/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 64, in <module>
    from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: dlopen(/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): no suitable image found.  Did find:
	/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture
	/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/__init__.py", line 39, in <module>
    from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
  File "/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 83, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 64, in <module>
    from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: dlopen(/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): no suitable image found.  Did find:
	/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture
	/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.
>>>
(tensorflow_macos_venv) mike@mikechendeMacBook-Pro ~ % uname -m
arm64
(tensorflow_macos_venv) mike@mikechendeMacBook-Pro ~ % file $(which python)
/Users/mike/tensorflow_macos_venv/bin/python: Mach-O 64-bit executable arm64
(tensorflow_macos_venv) mike@mikechendeMacBook-Pro ~ % clear
(tensorflow_macos_venv) mike@mikechendeMacBook-Pro ~ % uname -m
arm64
(tensorflow_macos_venv) mike@mikechendeMacBook-Pro ~ % file $(which python)
/Users/mike/tensorflow_macos_venv/bin/python: Mach-O 64-bit executable arm64
(tensorflow_macos_venv) mike@mikechendeMacBook-Pro ~ % python
Python 3.8.7 (default, Dec 30 2020, 02:09:32)
[Clang 12.0.0 (clang-1200.0.32.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
  File "/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 64, in <module>
    from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: dlopen(/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): no suitable image found.  Did find:
	/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture
	/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/__init__.py", line 39, in <module>
    from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
  File "/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 83, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 64, in <module>
    from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: dlopen(/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): no suitable image found.  Did find:
	/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture
	/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

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

by the way numpy is not work too

 import numpy
Traceback (most recent call last):
  File "/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/numpy/core/__init__.py", line 24, in <module>
    from . import multiarray
  File "/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/numpy/core/multiarray.py", line 14, in <module>
    from . import overrides
  File "/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/numpy/core/overrides.py", line 7, in <module>
    from numpy.core._multiarray_umath import (
ImportError: dlopen(/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so, 2): no suitable image found.  Did find:
	/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so: mach-o, but wrong architecture
	/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so: mach-o, but wrong architecture

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/numpy/__init__.py", line 142, in <module>
    from . import core
  File "/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/numpy/core/__init__.py", line 50, in <module>
    raise ImportError(msg)
ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.8 from "/Users/mike/tensorflow_macos_venv/bin/python"
  * The NumPy version is: "1.18.5"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: dlopen(/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so, 2): no suitable image found.  Did find:
	/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so: mach-o, but wrong architecture
	/Users/mike/tensorflow_macos_venv/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so: mach-o, but wrong architecture

@asd3427
Copy link

asd3427 commented Feb 1, 2021

i can use tensorflow on m1 now!!!!!!!! just need to watch this videos is very simple , hope can help others

@white-collar
Copy link
Author

@asd3427 do I need to install XCode command tools only or XCode itself as well ? Which version of python do you have ?

@asd3427
Copy link

asd3427 commented Feb 2, 2021

@asd3427 do I need to install XCode command tools only or XCode itself as well ? Which version of python do you have ?
i was install xcode command tools and homebrew im not sure did it need xcode.......... and my python version is 3.8.7
to install it you need
berw install python@3.8
and test did python3 is 3.8 then follow that video to install tensorflow

@mwidjaja1
Copy link

If you'd rather install TensorFlow in a Conda Python Environment, you can follow these: #153

@ThomasMerkh
Copy link

Also same problem:

(tensorflow_macos_venv) lastname@firstname-MacBook-Pro ~ % python
Python 3.8.6 (v3.8.6:db455296be, Sep 23 2020, 13:31:39)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

import tensorflow as tf
Traceback (most recent call last):
File "/Users/lastname/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: dlopen(/Users/lastname/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): no suitable image found. Did find:
/Users/lastname/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture
/Users/lastname/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 1, in
File "/Users/lastname/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/init.py", line 41, in
from tensorflow.python.tools import module_util as _module_util
File "/Users/lastname/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/init.py", line 39, in
from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
File "/Users/lastname/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 83, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/Users/lastname/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: dlopen(/Users/lastname/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): no suitable image found. Did find:
/Users/lastname/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture
/Users/lastname/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture

Failed to load the native TensorFlow runtime.

@chinitaberrio
Copy link

Make sure you have installed xcode (download the latest version and install it): https://developer.apple.com/download/more/?=command%20line%20tools

Then in a terminal paste
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/chinitaberrio/tensorflow_macos/master/scripts/download_and_install.sh)

I added the python version that comes with Xcode, That should fix the issue :)

@diracdeltas
Copy link

i encountered the same error while running the venv in tmux. i disabled rosettta for terminal, but uname -m inside tmux still returned x86. it works fine outside tmux.

@hjmr
Copy link

hjmr commented Feb 18, 2021

(Updated on 3 Mar. 2021: Python 3.8.7 -> Python 3.8.8)
What I did to use TensorFlow on my M1 Mac with Pyenv and Poetry is ...

  1. Install Python 3.8.8 through Pyenv with a patch provided by Homebrew:
$ PYTHON_CONFIGURE_OPTS="--enable-framework" \
pyenv install --patch 3.8.8 << (curl -sSL "https://raw.githubusercontent.com/Homebrew/formula-patches/9811be33170a8f31a684fae6955542e31eb4e61e/python/3.8.7.patch")
  1. Make a project directory and set 3.8.8 as a default to the project:
$ mkdir my_project
$ cd my_project
$ pyenv local 3.8.8
  1. Initialize virtual environment using Poetry:
$ poetry init -n
  1. Add provided packages:
$ poetry add ../tensorflow_macos/arm64/numpy-1.18.5-cp38-cp38-macosx_11_0_arm64.whl
$ poetry add ../tensorflow_macos/arm64/grpcio-1.33.2-cp38-cp38-macosx_11_0_arm64.whl
$ poetry add ../tensorflow_macos/arm64/h5py-2.10.0-cp38-cp38-macosx_11_0_arm64.whl
  1. Install TensorFlow addons:
$ poetry add ../tensorflow_macos/arm64/tensorflow_addons_macos-0.1a2-cp38-cp38-macosx_11_0_arm64.whl
  1. Install TensorFlow for macOS using pip. It can't be installed using Poetry because of dependency problems:
$ poetry run pip install --no-dependencies ../tensorflow_macos/arm64/tensorflow_macos-0.1a2-cp38-cp38-macosx_11_0_arm64.whl
  1. Install some other packages required to run TensorFlow:
$ poetry add absl-py astunparse flatbuffers gast google_pasta keras_preprocessing opt_einsum protobuf tensorflow_estimator termcolor typing_extensions wrapt wheel tensorboard typeguard
  1. Then you will get it works:
$ poetry run python
Python 3.8.8 (default, Feb 22 2021, 09:50:21) 
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> 

@Clifford-Yen
Copy link

So what works for me is: Don't use the built-in Python 3.8 to create the virtual environment!

Instead, installing Python 3.8 with natively supported Homebrew (so your Python 3.8 path will be something like /opt/homebrew/Cellar/python@3.8/3.8.7/bin/python3.8), and use this Python 3.8 to create the virtual environment, then everything will be fine.

Otherwise, I always got the wrong architecture error when importing Tensorflow as long as I created the virtual environment with the built-in Python 3.8 (/usr/bin/python3).

Hope this helps!

@tahuang1991
Copy link

i also found the python must be installed from Command line tool! otherwise the python3.8 is not supporting the ARM arch and it would not load tensorflow even if you can install it without error. I hope the it could be emphasized

@basillatif
Copy link

I had a similar issue where it was showing that I had 2 architectures and both of them were wrong. First, check the your Python version with python3 --version to see if you have version 3.8 or 3.9. Next do which python3 to find the path of your Python installation. I had a version installed from Python directly as well as one from brew which were conflicting. I did brew uninstall python3 and it fixed my problem.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests