我有一台配备 M1 处理器的新款 MacBook Pro,它是基于 ARM 的处理器,当我尝试使用 python 编程语言获取我的设备的处理器类型时,它告诉我这是一个英特尔处理器“i386”!怎么会发生这种事。
代码:
*import platform
platform.processor()
Out[4]: 'i386'*
最佳答案
让我们从结论开始:
是,在Python3版本<= 3.9.1下是正确的,您可以通过 isapplesiliconready.com 查看此信息,表明Python版本大于3.9.1时支持m1芯片。正如您所说,您使用的是 Spyder IDE
,它可能由 Anaconda
控制,目前还不支持 m1 芯片。
那么,为什么?
原因是Rosetta
,遵循official link ,它向您展示了旧应用程序如何在 m1 芯片下运行,基本上您只需要知道大多数旧应用程序都在兼容模式
下运行,除非开发人员发布了专门编写或优化的版本m1芯片。那么Rosstta
做了什么?当您需要运行旧应用程序时,它只是假装您正在使用Intel芯片
,因此,结果与Intel芯片
相同。
如何解决此案?
灵感来自this answer ,虽然函数名变了,但是仍然可以用来解决这种情况,代码如下。
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
}
关于python - 使用 python 获取 Apple M1 处理器的处理器类型给我一个 Intel 处理器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66842004/