Get the processor type using python for Apple M1 processor gives me an Intel processor

Viewed 1654

I have the new MacBook Pro with M1 processor which is ARM based processor, when I try to get the processor type of my device using python programming language it tells me this is an Intel processor 'i386' !! how could that happen.

Code:

*import platform

platform.processor()
Out[4]: 'i386'*
2 Answers

Let's start with the conclusion:

Yes, it's correct under the Python3 version <= 3.9.1, you can check this info thourgh the isapplesiliconready.com, it shown the Python was supported the m1 chip when it version greater than 3.9.1. As you were said, you're using Spyder IDE which may controlled by the Anaconda, it doesn't support m1 chip so far.


So, Why?

The reason is Rosetta, follow the official link, it show you how the old app running under m1 chip, basicial you just need to know is most of the old apps was running in compatibility mode unless the developer release the version which was sepcial written or optimized for m1 chip. So what was the Rosstta done? It just pseudo you were using Intel chip when you need to run an old app, thus, the result is same whit Intel chip.


How to solve this case?

Inspired by this answer, although the function name was changed, but it still can be used to solve this case, here is the code.

import cpuinfo

# Just get the manufacturer of the processors

manufacturer = cpuinfo.get_cpu_info().get('brand_raw')
# 'Apple M1 Pro'

arch = 'arm' if 'm1' in manufacturer.lower() else 'x86_64'

# You can get all the info through the `get_cpu_info_json()`, like below.

>>> cpuinfo.get_cpu_info_json()

{
  "python_version": "3.9.7.final.0 (64 bit)",
  "cpuinfo_version": [
    8,
    0,
    0
  ],
  "cpuinfo_version_string": "8.0.0",
  "arch": "X86_64",
  "bits": 64,
  "count": 10,
  "arch_string_raw": "x86_64",
  "brand_raw": "Apple M1 Pro",
  "hz_actual_friendly": "2.4000 GHz",
  "hz_actual": [
    2400000000,
    0
  ],
  "family": 6,
  "flags": [
    "acpi",
    "aes",
    "apic",
    "clflush",
    "clfsh",
    "cmov",
    "cx16",
    "cx8",
    "de",
    "ds",
    "dscpl",
    "dtes64",
    "dtse64",
    "est",
    "fpu",
    "fxsr",
    "htt",
    "lahf_lm",
    "mca",
    "mce",
    "mmx",
    "mon",
    "monitor",
    "msr",
    "mtrr",
    "pae",
    "pat",
    "pbe",
    "pclmulqdq",
    "pdcm",
    "pge",
    "pni",
    "popcnt",
    "pse",
    "pse36",
    "seglim64",
    "sep",
    "ss",
    "sse",
    "sse2",
    "sse3",
    "sse4.1",
    "sse4.2",
    "sse4_1",
    "sse4_2",
    "ssse3",
    "tm",
    "tm2",
    "tpr",
    "tsc",
    "vme",
    "vmx"
  ],
  "vendor_id_raw": "GenuineIntel",
  "hz_advertised_friendly": "2.5000 GHz",
  "hz_advertised": [
    2500000000,
    0
  ],
  "l2_cache_size": 65536,
  "l2_cache_line_size": 8192,
  "l2_cache_associativity": 8,
  "model": 44
}

the same thing happens to me but only under spyder. if I do it under command line python3, I get the correct result!

Related