简体   繁体   English

MacOS M1 系统被 Python package 检测为 ARM,即使我使用的是 Rosetta

[英]MacOS M1 system is detected as ARM by Python package even though I'm using Rosetta

I'm on a Macbook with M1 (Apple ARM architecture) and I've tried running the following Python code using the layoutparser library, which indirectly uses pycocotools :我在带有 M1(Apple ARM 架构)的 Macbook 上,我尝试使用layoutparser库运行以下 Python 代码,该库间接使用pycocotools

import layoutparser as lp
lp.Detectron2LayoutModel()

And I've received the error:我收到了错误:

[...]
ImportError: 
dlopen([...]/.venv/lib/python3.9/site-packages/pycocotools/_mask.cpython-39-darwin.so, 0x0002): 
tried: 
'[...]/.venv/lib/python3.9/site-packages/pycocotools/_mask.cpython-39-darwin.so' 
(mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), 
'/usr/local/lib/_mask.cpython-39-darwin.so' (no such file), 
'/usr/lib/_mask.cpython-39-darwin.so' (no such file)

The crucial info for me seems to be [...] is an incompatible architecture (have 'x86_64', need 'arm64e') [...] .对我来说,关键信息似乎是[...] is an incompatible architecture (have 'x86_64', need 'arm64e') [...] Indeed, I am using the Apple ARM architecture, and sometimes it is not supported by some software.确实,我用的是苹果ARM架构,有时候有些软件不支持。 This is usually solved by using Rosetta, which simulates an Intel-x64 architecture.这通常通过使用模拟 Intel-x64 架构的 Rosetta 来解决。 So I start a terminal with Rosetta ( arch -x86_64 zsh ), create a new virtual environment, make a fresh install of the dependencies, and try to run the code again...所以我用 Rosetta ( arch -x86_64 zsh ) 启动一个终端,创建一个新的虚拟环境,重新安装依赖项,然后尝试再次运行代码......

... and I receive the same error that I had also had without Rosetta: ...我收到了与没有 Rosetta 的情况相同的错误:

[...] is an incompatible architecture (have 'x86_64', need 'arm64e') [...]

I've double-checked that Rosetta is really activated:我已经仔细检查了 Rosetta 是否真的被激活:

> uname -m
x86_64

Rosetta seems to be working.罗塞塔似乎在工作。 And yet, according to the error message, it seems not to be working.然而,根据错误消息,它似乎不起作用。

Any ideas what could be the problem with Rosetta, or the library, or whatever, and how I could try fixing it?任何想法可能是 Rosetta 或图书馆或其他任何问题,以及我如何尝试修复它?

Charles Duffy explained the problem in the comments, thank you! Charles Duffy在评论中解释了问题,谢谢!

When I checked the platform in Python, it was indeed ARM:当我查看Python中的平台时,确实是ARM:

> python -c 'import platform; print(platform.platform())'
macOS-12.0.1-arm64-i386-64bit

So I had been using a Python installation for ARM.所以我一直在为 ARM 使用 Python 安装。

Now I installed brew and then python3 from the Rosetta terminal and used the newly installed Python to initiate a fresh virtual environment, and this fixed it.现在我从 Rosetta 终端安装了brewpython3 ,并使用新安装的 Python 启动了一个新的虚拟环境,这修复了它。

( This article helped me a bit with it.) 这篇文章对我有所帮助。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM