【问题标题】:"mach-o, but wrong architecture" when importing regex导入正则表达式时出现“mach-o,但架构错误”
【发布时间】:2013-03-24 21:31:59
【问题描述】:

当我尝试import regex 时出现以下错误。

Traceback (most recent call last):
  File "app.py", line 3, in <module>
    import regex 
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/regex.py", line 391, in <module>
    import _regex_core
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/_regex_core.py", line 21, in <module>
    import _regex
ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/_regex.so, 2): no suitable image found.  Did find:
    /opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/_regex.so: mach-o, but wrong architecture

我已经通过 macports 安装了 python33,然后通过 sudo python setup.py install 安装了最新版本的正则表达式(Matthew Barnett)。

我正在使用 Mac Os X Leopard (8.5)。我的处理器是 64 位的 Core 2 Duo。我该如何解决这个错误?

当我运行lipo -info 时,我得到:

Non-fat file: /opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/_regex.so is architecture: i386

当我运行lipo -info /opt/local/bin/python 非胖文件:/opt/local/bin/python 是架构:ppc7400

为什么是python ppc7400?

【问题讨论】:

  • 您确定您使用的是 3.3 python 二进制文件吗?
  • 查看库路径:这强烈表明 Python 3.3 正在运行。
  • 当我在终端上运行 python 时,我得到: Python 3.3.0 (default, Mar 24 2013, 16:14:43) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin 键入“help”、“copyright”、“credits”或“license”以获取更多信息。 >>>

标签: python macos macports osx-leopard python-3.3


【解决方案1】:

MacPorts 有自己的用于 Python 3.3 的 regex 库端口,那么为什么不使用它而不是自己构建它呢?

$ sudo port install py33-regex
[...]
$ python3.3
Python 3.3.0 (default, Nov 23 2012, 10:26:01) 
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import regex
>>> regex.match(r'[a-z]+', 'abc123').group(0)
'abc'

ppc7400 架构更广为人知的是 PowerPC G4,它是您运行的 OS X 版本支持的架构之一。看起来好像您已经设法安装了 Python 3.3 的 PowerPC 版本。 (大概是通过 Rosetta 运行的。)

发生这种情况的一种情况是,如果您曾经在 PowerPC G4 机器上安装过 MacPorts,然后使用迁移助手将安装转移到新的 Intel 机器上。请参阅有关主题的MacPorts FAQ

MacPorts 适用于基于 Intel 和 PowerPC 的 Mac,但默认情况下,您安装的端口将仅针对您当前运行的架构进行编译。这意味着,如果您从 PowerPC Mac 迁移到 Intel 并使用迁移助手将数据复制到新机器上,您应该在新机器上重新安装所有端口,以便为 Intel 重建它们。请参阅 Migration 了解如何让事情再次正常运行。

(另外,您不需要使用lipofile 实用程序会告诉您可执行文件或共享库中的架构。)

【讨论】:

  • 我用 macports 安装了正则表达式,现在它可以正确导入。然而,那是因为它现在也是为 ppc7400 架构而构建的。这是为什么呢?
  • 我还没有从 PowerPC 迁移。 :)
  • /opt/local/etc/macports/macports.conf 中的build_archuniversal_archs 有哪些设置?
  • 在 macports.conf 我有:'universal_archs ppc i386' 但没有提到 build_arch。
  • 您可以尝试将universal_archs 设置为x86_64 i386,然后使用+universal 选项卸载并重新构建python33 端口。或者阅读更多 MacPorts 文档...
猜你喜欢
  • 2020-05-03
  • 2017-01-21
  • 2012-09-16
  • 2011-01-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-20
相关资源
最近更新 更多