emsdk python版本错误问题解决

问题:

wasm官网引导安装emsdk的时候可能会出现以下报错:

Traceback (most recent call last):
  File "./emsdk", line 803, in xcode_sdk_version
    return subprocess.check_output(['xcrun', '--show-sdk-version']).strip().split('.')
TypeError: a bytes-like object is required, not 'str'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./emsdk", line 2385, in <module>
    sys.exit(main())
  File "./emsdk", line 2368, in main
    success = tool.install()
  File "./emsdk", line 1351, in install
    success = tool.install()
  File "./emsdk", line 1361, in install
    success = build_llvm_tool(self)
  File "./emsdk", line 856, in build_llvm_tool
    if OSX and (not os.environ.get('LLVM_CMAKE_ARGS') or not 'HAVE_FUTIMENS' in os.environ.get('LLVM_CMAKE_ARGS')) and xcode_sdk_version() < [10,13]:
  File "./emsdk", line 805, in xcode_sdk_version
    return subprocess.checkplatform.mac_ver()[0].split('.')
AttributeError: module 'subprocess' has no attribute 'checkplatform'

原因:

你当前运行环境的python版本是python3

解决方法:

  1. 切换python版本:
    可以直接改变当前终端python的环境或者修改根目录下emsdk文件开头指定的python运行环境等

  2. 对python3做特殊处理:
    打开根目录下的emsdk文件,修改以下两处地方

    • line803:
      if sys.version_info >= (3,):
      return subprocess.check_output(['xcrun', '--show-sdk-version']).decode('utf8').strip().split('.')
      else:
      return subprocess.check_output(['xcrun', '--show-sdk-version']).strip().split('.')
      
    • line859:
      if OSX and (not os.environ.get('LLVM_CMAKE_ARGS') or not 'HAVE_FUTIMENS' in os.environ.get('LLVM_CMAKE_ARGS')) and xcode_sdk_version() < ['10','13']: