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

M1 wrong architecture after install script #21

Closed
tomjefferis opened this issue Nov 20, 2020 · 20 comments
Closed

M1 wrong architecture after install script #21

tomjefferis opened this issue Nov 20, 2020 · 20 comments

Comments

@tomjefferis
Copy link

Im getting an error in my terminal when trying to run.

heres my trace:

/Users/tomjefferis/tensorflow_macos_venv/bin/python /Users/tomjefferis/PycharmProjects/pythonProject/test.py
Traceback (most recent call last):
File "/Users/tomjefferis/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/tomjefferis/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): no suitable image found. Did find:
/Users/tomjefferis/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture
/Users/tomjefferis/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 "/Users/tomjefferis/PycharmProjects/pythonProject/test.py", line 2, in
from tensorflow.python.compiler.mlcompute import mlcompute
File "/Users/tomjefferis/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/tomjefferis/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/tomjefferis/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/tomjefferis/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/tomjefferis/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): no suitable image found. Did find:
/Users/tomjefferis/tensorflow_macos_venv/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture
/Users/tomjefferis/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.

Process finished with exit code 1

@Willian-Zhang
Copy link

Willian-Zhang commented Nov 20, 2020

Could you paste your result for file $(which python)

@fzzfbyx
Copy link

fzzfbyx commented Nov 20, 2020

I have exactly the same situation, in the MacBook m1 virtual python environment when import tensorflow it occurs that error, don't know what to do...

@fzzfbyx
Copy link

fzzfbyx commented Nov 20, 2020

截屏2020-11-21 上午12 23 56

@Willian-Zhang could you give us some advice please?

@Willian-Zhang
Copy link

@fzzfbyx Please paste your result for file $(which python) on that env,
a reference for proper setup:

image

@tomjefferis
Copy link
Author

file $(which python)

The output:

$ file $(which python)
/Users/tomjefferis/tensorflow/bin/python: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64:Mach-O 64-bit executable arm64]
/Users/tomjefferis/tensorflow/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
/Users/tomjefferis/tensorflow/bin/python (for architecture arm64): Mach-O 64-bit executable arm64

I have exactly the same situation, in the MacBook m1 virtual python environment when import tensorflow it occurs that error, don't know what to do...

Possible workaround, worked for me in vscode and terminal:

  • Download release from github and extract
  • Create new python virtual environment
  • Run the script to install to the newly created virtual environment

Switching to this environment in terminal I was able to import tensorflow mac and selecting this as the interpreter in vscode I was able to do the same where as before it was giving me the errors.

@Willian-Zhang
Copy link

Willian-Zhang commented Nov 20, 2020

@tomjefferis if you are having trouble running in vscode, please consider checking out beta version of it:
https://code.visualstudio.com/docs/?dv=darwinarm64&build=insiders

It might also be possible work out via to setup vscode integrated terminal to use external terminal.

@tomjefferis
Copy link
Author

@Willian-Zhang Its working in vscode but not in pycharm

@fzzfbyx
Copy link

fzzfbyx commented Nov 20, 2020

file $(which python)

The output:

$ file $(which python)
/Users/tomjefferis/tensorflow/bin/python: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64:Mach-O 64-bit executable arm64]
/Users/tomjefferis/tensorflow/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
/Users/tomjefferis/tensorflow/bin/python (for architecture arm64): Mach-O 64-bit executable arm64

I have exactly the same situation, in the MacBook m1 virtual python environment when import tensorflow it occurs that error, don't know what to do...

Possible workaround, worked for me in vscode and terminal:

  • Download release from github and extract
  • Create new python virtual environment
  • Run the script to install to the newly created virtual environment

Switching to this environment in terminal I was able to import tensorflow mac and selecting this as the interpreter in vscode I was able to do the same where as before it was giving me the errors.

thank you for replying. But in the first time I already do that. create a new env, run the script, in the env I can find the package but can't import. what else did you do to solve this problem?

@hoytak
Copy link
Collaborator

hoytak commented Dec 11, 2020

To clarify what is happening here for others encountering this issue.

There are two cpu subtypes for binary files on the M1, arm64 and arm64e. Trying to mix the two results in the error you see. For this pre-release version, we're focusing support on the arm64 version of python in the Xcode Command Line Tools, and the included wheel does not include an arm64e slice. To make sure you have the correct version of python run file $(which python) and it should display an arm64 slice, not an arm64e slice.

If you encounter this problem, install the Python version from Xcode Command Line Tools, then pass the path to that version into the install script using --python=/Library/Developer/CommandLineTools/usr/bin/python3.

@chinitaberrio
Copy link

Hi @hoytak, This is my first MacBook and I'm very confused about how to solve this issue, I got
/usr/bin/python: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64e:Mach-O 64-bit executable arm64e] /usr/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64 /usr/bin/python (for architecture arm64e): Mach-O 64-bit executable arm64e

I have Xcode installed, Could you please elaborate a bit more the way to solve it?

Thanks

@EthanDamien
Copy link

@hoytak, I agree with @chinitaberrio here. I'm not sure how I can change the python version so it is arm64e. I am also very new to MacBook and the instructions are not very clear. I installed using homebrew because I don't know how to install using command-line tools. What do I type in and where? I cannot find any advice anywhere else.

@chinitaberrio
Copy link

chinitaberrio commented Feb 12, 2021

@hoytak, I agree with @chinitaberrio here. I'm not sure how I can change the python version so it is arm64e. I am also very new to MacBook and the instructions are not very clear. I installed using homebrew because I don't know how to install using command-line tools. What do I type in and where? I cannot find any advice anywhere else.

I got this issue fixed in my repo https://github.com/chinitaberrio/tensorflow_macos
just 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)"
That should fix the issue :)

@EthanDamien
Copy link

@hoytak, I agree with @chinitaberrio here. I'm not sure how I can change the python version so it is arm64e. I am also very new to MacBook and the instructions are not very clear. I installed using homebrew because I don't know how to install using command-line tools. What do I type in and where? I cannot find any advice anywhere else.

I got this issue fixed in my repo https://github.com/chinitaberrio/tensorflow_macos
just 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)"
That should fix the issue :)

Thank you so much! I really appreciate this!

@mbeavitt
Copy link

I'm having a very similar problem trying to run matplotlib inside a virtual environment. I hope this isn't the wrong place to ask about it. Here's the errror I get if I try to use matplotlib in ipython:

ImportError: dlopen(/Users/michaelbeavitt/.local/share/virtualenvs/michaelbeavitt-n2nhR21r/lib/python3.8/site-packages/PIL/_imaging.cpython-38-darwin.so, 2): no suitable image found. Did find:
/Users/michaelbeavitt/.local/share/virtualenvs/michaelbeavitt-n2nhR21r/lib/python3.8/site-packages/PIL/_imaging.cpython-38-darwin.so: mach-o, but wrong architecture
/Users/michaelbeavitt/.local/share/virtualenvs/michaelbeavitt-n2nhR21r/lib/python3.8/site-packages/PIL/_imaging.cpython-38-darwin.so: mach-o, but wrong architecture

here's the results of the which command:

(michaelbeavitt) michaelbeavitt@Michaels-MacBook-Air ~ % file $(which python)
/Users/michaelbeavitt/.local/share/virtualenvs/michaelbeavitt-n2nhR21r/bin/python: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64:Mach-O 64-bit executable arm64]
/Users/michaelbeavitt/.local/share/virtualenvs/michaelbeavitt-n2nhR21r/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
/Users/michaelbeavitt/.local/share/virtualenvs/michaelbeavitt-n2nhR21r/bin/python (for architecture arm64): Mach-O 64-bit executable arm64

Any ideas?

@chinitaberrio
Copy link

chinitaberrio commented Feb 15, 2021

@mbeavitt I think the problem is with Pillow instead. I had a problem installing matplotlib but I fixed it by doing brew install libjpeg before installing matplotlib.

@mbeavitt
Copy link

Thanks for your advice! Unfortunately that didn't seem to change anything. Here is the full read-out when I try to use matplotlib in the python shell:

In [2]: import matplotlib.pyplot as plt
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-a0d2faabd9e9> in <module>
----> 1 import matplotlib.pyplot as plt

~/.local/share/virtualenvs/michaelbeavitt-n2nhR21r/lib/python3.8/site-packages/matplotlib/pyplot.py in <module>
     34 from cycler import cycler
     35 import matplotlib
---> 36 import matplotlib.colorbar
     37 import matplotlib.image
     38 from matplotlib import rcsetup, style

~/.local/share/virtualenvs/michaelbeavitt-n2nhR21r/lib/python3.8/site-packages/matplotlib/colorbar.py in <module>
     42 import matplotlib.collections as collections
     43 import matplotlib.colors as colors
---> 44 import matplotlib.contour as contour
     45 import matplotlib.cm as cm
     46 import matplotlib.gridspec as gridspec

~/.local/share/virtualenvs/michaelbeavitt-n2nhR21r/lib/python3.8/site-packages/matplotlib/contour.py in <module>
     15 import matplotlib.collections as mcoll
     16 import matplotlib.font_manager as font_manager
---> 17 import matplotlib.text as text
     18 import matplotlib.cbook as cbook
     19 import matplotlib.mathtext as mathtext

~/.local/share/virtualenvs/michaelbeavitt-n2nhR21r/lib/python3.8/site-packages/matplotlib/text.py in <module>
     14 from .font_manager import FontProperties
     15 from .patches import FancyArrowPatch, FancyBboxPatch, Rectangle
---> 16 from .textpath import TextPath  # Unused, but imported by others.
     17 from .transforms import (
     18     Affine2D, Bbox, BboxBase, BboxTransformTo, IdentityTransform, Transform)

~/.local/share/virtualenvs/michaelbeavitt-n2nhR21r/lib/python3.8/site-packages/matplotlib/textpath.py in <module>
      9 from matplotlib.font_manager import FontProperties, get_font
     10 from matplotlib.ft2font import LOAD_NO_HINTING, LOAD_TARGET_LIGHT
---> 11 from matplotlib.mathtext import MathTextParser
     12 from matplotlib.path import Path
     13 from matplotlib.transforms import Affine2D

~/.local/share/virtualenvs/michaelbeavitt-n2nhR21r/lib/python3.8/site-packages/matplotlib/mathtext.py in <module>
     25 
     26 import numpy as np
---> 27 from PIL import Image
     28 from pyparsing import (
     29     Combine, Empty, FollowedBy, Forward, Group, Literal, oneOf, OneOrMore,

~/.local/share/virtualenvs/michaelbeavitt-n2nhR21r/lib/python3.8/site-packages/PIL/Image.py in <module>
     92     # Also note that Image.core is not a publicly documented interface,
     93     # and should be considered private and subject to change.
---> 94     from . import _imaging as core
     95 
     96     if __version__ != getattr(core, "PILLOW_VERSION", None):

ImportError: dlopen(/Users/michaelbeavitt/.local/share/virtualenvs/michaelbeavitt-n2nhR21r/lib/python3.8/site-packages/PIL/_imaging.cpython-38-darwin.so, 2): no suitable image found.  Did find:
	/Users/michaelbeavitt/.local/share/virtualenvs/michaelbeavitt-n2nhR21r/lib/python3.8/site-packages/PIL/_imaging.cpython-38-darwin.so: mach-o, but wrong architecture
	/Users/michaelbeavitt/.local/share/virtualenvs/michaelbeavitt-n2nhR21r/lib/python3.8/site-packages/PIL/_imaging.cpython-38-darwin.so: mach-o, but wrong architecture

@chinitaberrio
Copy link

@mbeavitt Have you tried uninstalling pillow and matplotlib?
Pillow have also versions for M1 -> https://pypi.org/project/Pillow/8.0.1/#files
I found this, hope it helps you.

S.

@C-osmin
Copy link

C-osmin commented May 4, 2021

There are a lot of Python related libraries that I can't use on the new M1 Mac. Can't use pygame module, managed to install pygame==1.9.6 but when I run the scripts with pygame imported I get the good old
"mach-o, but wrong architecture".

Traceback (most recent call last):
  File "/Users/Mike/games/spaceinvaders/main.py", line 1, in <module>
    import pygame
  File "/Users/Mike/games/venv/lib/python3.9/site-packages/pygame/__init__.py", line 120, in <module>
    from pygame.base import *
ImportError: dlopen(/Users/Mike/games/venv/lib/python3.9/site-packages/pygame/base.cpython-39-darwin.so, 2): no suitable image found.  Did find:
        /Users/Mike/games/venv/lib/python3.9/site-packages/pygame/base.cpython-39-darwin.so: mach-o, but wrong architecture
        /Users/Mike/games/venv/lib/python3.9/site-packages/pygame/base.cpython-39-darwin.so: mach-o, but wrong architect

Same goes for pyais library, and many others.
There's got to be a global solution or the M1 architecture is really crap.

@TrentConley
Copy link

I'm having a similar issue, but with matplotlib. I looked at previous threads about the issue, but nothing solved the problem completely. When I run a program that involves matplotlib, this is my error message:
Traceback (most recent call last):
File "ideal-gas-simulation.py", line 13, in
import matplotlib.pyplot as plt
File "/Users/trentconley/Library/Python/3.8/lib/python/site-packages/matplotlib/init.py", line 107, in
from . import _api, cbook, docstring, rcsetup
File "/Users/trentconley/Library/Python/3.8/lib/python/site-packages/matplotlib/rcsetup.py", line 24, in
from matplotlib import _api, animation, cbook
File "/Users/trentconley/Library/Python/3.8/lib/python/site-packages/matplotlib/animation.py", line 34, in
from PIL import Image
File "/Users/trentconley/Library/Python/3.8/lib/python/site-packages/PIL/Image.py", line 94, in
from . import _imaging as core
ImportError: dlopen(/Users/trentconley/Library/Python/3.8/lib/python/site-packages/PIL/_imaging.cpython-38-darwin.so, 2): no suitable image found. Did find:
/Users/trentconley/Library/Python/3.8/lib/python/site-packages/PIL/_imaging.cpython-38-darwin.so: mach-o, but wrong architecture
/Users/trentconley/Library/Python/3.8/lib/python/site-packages/PIL/_imaging.cpython-38-darwin.so: mach-o, but wrong architecture

@L1uNan
Copy link

L1uNan commented May 19, 2021

I'm having a similar issue, but with pydantic.

File "/Users/L/Library/Caches/pypoetry/virtualenvs/school-backend-NxQ28yof-py3.9/lib/python3.9/site-packages/uvicorn/importer.py", line 20, in import_from_string module = importlib.import_module(module_str) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1030, in _gcd_import File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 855, in exec_module File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File "/Users/L/Documents/sensorsPro/miniprogram_backend/./miniprogram_backend/main.py", line 4, in <module> from fastapi import FastAPI File "/Users/L/Library/Caches/pypoetry/virtualenvs/school-backend-NxQ28yof-py3.9/lib/python3.9/site-packages/fastapi/__init__.py", line 7, in <module> from .applications import FastAPI as FastAPI File "/Users/L/Library/Caches/pypoetry/virtualenvs/school-backend-NxQ28yof-py3.9/lib/python3.9/site-packages/fastapi/applications.py", line 3, in <module> from fastapi import routing File "/Users/L/Library/Caches/pypoetry/virtualenvs/school-backend-NxQ28yof-py3.9/lib/python3.9/site-packages/fastapi/routing.py", line 18, in <module> from fastapi import params File "/Users/L/Library/Caches/pypoetry/virtualenvs/school-backend-NxQ28yof-py3.9/lib/python3.9/site-packages/fastapi/params.py", line 4, in <module> from pydantic.fields import FieldInfo ImportError: dlopen(/Users/L/Library/Caches/pypoetry/virtualenvs/school-backend-NxQ28yof-py3.9/lib/python3.9/site-packages/pydantic/__init__.cpython-39-darwin.so, 2): no suitable image found. Did find: /Users/L/Library/Caches/pypoetry/virtualenvs/school-backend-NxQ28yof-py3.9/lib/python3.9/site-packages/pydantic/__init__.cpython-39-darwin.so: mach-o, but wrong architecture /Users/L/Library/Caches/pypoetry/virtualenvs/school-backend-NxQ28yof-py3.9/lib/python3.9/site-packages/pydantic/__init__.cpython-39-darwin.so: mach-o, but wrong architecture

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

10 participants