python 如何檢查使用 arm 電腦

解法,檢查有無 “-arm” 即可。

在 macOS x86 取得 platform.platform()

macOS-10.15.7-x86_64-i386-64bit

在 macOS arm:

macOS-12.0.1-arm64-i386-64bit

資料來源:
https://stackoverflow.com/questions/70253218/macos-m1-system-is-detected-as-arm-by-python-package-even-though-im-using-roset

Charles Duffy explained the problem in the comments, thank you! 😃

When I checked the platform in Python, it was indeed 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.

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. (This article helped me a bit with it.)

Update:

When creating Python environments with conda, it is possible to specify whether they should use Apple ARM or Intel-x64:

  • CONDA_SUBDIR=osx-arm64 conda create -n my_env python makes an ARM environment
  • CONDA_SUBDIR=osx-64 conda create -n my_env python makes an x64 environment

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *