使用 python 获取处理器类型 for Apple M1 处理器给了我一个 Intel 处理器
Posted
技术标签:
【中文标题】使用 python 获取处理器类型 for Apple M1 处理器给了我一个 Intel 处理器【英文标题】:Get the processor type using python for Apple M1 processor gives me an Intel processor 【发布时间】:2021-06-24 18:17:08 【问题描述】:我有带有 M1 处理器的新 MacBook Pro,它是基于 ARM 的处理器,当我尝试使用 python 编程语言获取设备的处理器类型时,它告诉我这是一个英特尔处理器“i386”!怎么会这样。
代码:
*import platform
platform.processor()
Out[4]: 'i386'*
【问题讨论】:
它的 Python 3.8 ,Spyder IDE 是的,看起来它在这里的作用与它对 NetBSD 的作用相同。 docs.python.org/3/library/platform.html 哦,好吧。 【参考方案1】:让我们从结论开始:
是的,在Python3版本下是正确的3.9.1,你可以通过isapplesiliconready.com查看这个信息,它表明Python支持m1芯片版本大于 3.9.1 时。正如你所说,你使用的是Spyder IDE
,它可能由Anaconda
控制,目前还不支持m1芯片。
那么,为什么?
原因是Rosetta
,关注official link,它告诉你旧应用程序是如何在m1芯片下运行的,你只需要知道大部分旧应用程序都是在compatibility mode
运行的,除非开发者发布专为 m1 芯片编写或优化的版本。那么Rosstta
做了什么?当您需要运行旧应用程序时,它只是伪您使用Intel chip
,因此,结果与Intel chip
相同。
如何解决这个案子?
受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
【讨论】:
【参考方案2】:同样的事情发生在我身上,但只在 spyder 下。如果我在命令行 python3 下执行,我会得到正确的结果!
【讨论】:
以上是关于使用 python 获取处理器类型 for Apple M1 处理器给了我一个 Intel 处理器的主要内容,如果未能解决你的问题,请参考以下文章