【发布时间】:2022-01-22 08:47:29
【问题描述】:
我需要使用 Python 在不同平台上从 GitHub 下载 Go 程序的二进制文件
为了下载与当前平台匹配的二进制文件,我需要将当前平台信息翻译成与GOARCH and GOOS environment variables匹配的格式
在 NodeJS 中,我可以很简单地做到这一点:
function getArch() {
switch (process.arch) {
case 'x32': return '386'
case 'x64': return 'amd64'
case 'arm64': return 'arm64'
case 'arm': return 'armv7'
}
throw new Error(`architecture "${process.arch}" is not supported`)
}
function getPlatform() {
switch (process.platform) {
case 'darwin': return 'darwin'
case 'linux': return 'linux'
case 'win32': return 'windows'
}
throw new Error(`platform "${process.platform}" is not supported`)
}
但是对于 Python 来说,这似乎很难做到,因为标准库 platform 没有很好的规范,并且没有列出不同平台和架构的所有可能返回值
例如,platform.architecture() 将返回AMD64 用于具有amd64 CPU 的Windows 系统,但x86_64 用于具有相同CPU 的Linux 系统,这使得很难有一种优雅的方式来匹配每个我需要的平台
【问题讨论】:
标签: python python-3.x cross-platform