arch x86_64 和 arm64e 可用,但 python3 表示 Mac M1 上的架构不兼容

e.i*_*luf 7 python apple-m1

我正在尝试在 Mac M1 上运行此阅读文本 。当我尝试运行这段代码时

 python3 make_keras_charnet_model.py
Run Code Online (Sandbox Code Playgroud)

我收到错误


Using Theano backend.
Traceback (most recent call last):
  File "/Users/name/miniforge3/envs/ocr_env/lib/python3.8/site-packages/theano/gof/cutils.py", line 305, in <module>
    from cutils_ext.cutils_ext import *  # noqa
ImportError: dlopen(/Users/name/.theano/compiledir_macOS-12.0-arm64-i386-64bit-i386-3.8.6-64/cutils_ext/cutils_ext.so, 0x0002): tried: '/Users/name/.theano/compiledir_macOS-12.0-arm64-i386-64bit-i386-3.8.6-64/cutils_ext/cutils_ext.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/cutils_ext.so' (no such file), '/usr/lib/cutils_ext.so' (no such file)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/name/miniforge3/envs/ocr_env/lib/python3.8/site-packages/theano/gof/cutils.py", line 316, in <module>
    from cutils_ext.cutils_ext import *  # noqa
ImportError: dlopen(/Users/name/.theano/compiledir_macOS-12.0-arm64-i386-64bit-i386-3.8.6-64/cutils_ext/cutils_ext.so, 0x0002): tried: '/Users/name/.theano/compiledir_macOS-12.0-arm64-i386-64bit-i386-3.8.6-64/cutils_ext/cutils_ext.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/cutils_ext.so' (no such file), '/usr/lib/cutils_ext.so' (no such file)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "make_keras_charnet_model.py", line 10, in <module>
    from keras.models import Sequential, model_from_json
  File "/Users/name/miniforge3/envs/ocr_env/lib/python3.8/site-packages/keras/models.py", line 15, in <module>
    from . import backend as K
  File "/Users/name/miniforge3/envs/ocr_env/lib/python3.8/site-packages/keras/backend/__init__.py", line 47, in <module>
    from .theano_backend import *
  File "/Users/name/miniforge3/envs/ocr_env/lib/python3.8/site-packages/keras/backend/theano_backend.py", line 1, in <module>
    import theano
  File "/Users/name/miniforge3/envs/ocr_env/lib/python3.8/site-packages/theano/__init__.py", line 76, in <module>
    from theano.scan_module import scan, map, reduce, foldl, foldr, clone
  File "/Users/name/miniforge3/envs/ocr_env/lib/python3.8/site-packages/theano/scan_module/__init__.py", line 40, in <module>
    from theano.scan_module import scan_opt
  File "/Users/name/miniforge3/envs/ocr_env/lib/python3.8/site-packages/theano/scan_module/scan_opt.py", line 59, in <module>
    from theano import tensor, scalar
  File "/Users/name/miniforge3/envs/ocr_env/lib/python3.8/site-packages/theano/tensor/__init__.py", line 7, in <module>
    from theano.tensor.subtensor import *
  File "/Users/name/miniforge3/envs/ocr_env/lib/python3.8/site-packages/theano/tensor/subtensor.py", line 27, in <module>
    import theano.gof.cutils  # needed to import cutils_ext
  File "/Users/name/miniforge3/envs/ocr_env/lib/python3.8/site-packages/theano/gof/cutils.py", line 319, in <module>
    compile_cutils()
  File "/Users/name/miniforge3/envs/ocr_env/lib/python3.8/site-packages/theano/gof/cutils.py", line 283, in compile_cutils
    cmodule.GCC_compiler.compile_str('cutils_ext', code, location=loc,
  File "/Users/name/miniforge3/envs/ocr_env/lib/python3.8/site-packages/theano/gof/cmodule.py", line 2212, in compile_str
    return dlimport(lib_filename)
  File "/Users/name/miniforge3/envs/ocr_env/lib/python3.8/site-packages/theano/gof/cmodule.py", line 299, in dlimport
    rval = __import__(module_name, {}, {}, [module_name])
ImportError: dlopen(/Users/name/.theano/compiledir_macOS-12.0-arm64-i386-64bit-i386-3.8.6-64/cutils_ext/cutils_ext.so, 0x0002): tried: '/Users/name/.theano/compiledir_macOS-12.0-arm64-i386-64bit-i386-3.8.6-64/cutils_ext/cutils_ext.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/cutils_ext.so' (no such file), '/usr/lib/cutils_ext.so' (no such file)

Run Code Online (Sandbox Code Playgroud)

我已经复制了我的终端以使用 Rosetta 打开重复的终端,但仍然收到错误。

当我运行下面的命令来检查 M1 Mac 上可用的架构时

file /bin/bash

Run Code Online (Sandbox Code Playgroud)

我得到这个输出

/bin/bash:具有 2 个架构的 Mach-O 通用二进制文件:[x86_64:Mach-O 64 位可执行文件 x86_64] [arm64e:Mach-O 64 位可执行文件 arm64e]

/bin/bash(适用于架构 x86_64):Mach-O 64 位可执行文件 x86_64

/bin/bash(适用于arm64e架构):Mach-O 64位可执行arm64e

我看起来 x86_64 和 arm64e 都可用,但错误提示

(mach-o 文件,但是不兼容的体系结构(有“x86_64”,需要“arm64e”)),“/usr/local/lib/cutils_ext.so”(没有这样的文件),“/usr/lib/cutils_ext.so”。所以'(没有这样的文件)

是什么导致了这个错误?我该如何修复它?

luc*_*nos 18

我已经阅读了很多关于这个问题的信息,并且自从我从Python官方网站安装了python3-intel64以来,我就没有更多的麻烦了)

解决方案:

  1. 转到https://www.python.org/downloads/macos/
  2. 查找项目的 Python 版本
  3. 按“下载 macOS 64 位 universal2 安装程序”
  4. 从存档安装 Python(从那时起,您可以使用“python3-intel64”命令来运行 Python,而不仅仅是“python”)
  5. 从您安装的基本解释器在项目中创建新的 venv
  6. 将所有要求安装到 venv
  7. 利润!!!

  • 尝试、测试和批准 (2认同)

e.i*_*luf 4

我发现我需要指定架构

所以而不是

python3 make_keras_charnet_model.py
Run Code Online (Sandbox Code Playgroud)

我现在用这个

arch -arm64 python3 make_keras_charnet_model.py
Run Code Online (Sandbox Code Playgroud)