chromium - gn 脚本使用错误的 Python 版本运行(“需要类似字节的对象,而不是 'str'”)
问题描述
在 macOS(Catalina 10.15)上构建 Chromium 或 libwebrtc 时gn
,我从 Python 构建脚本中收到关于bytes
和str
. 例如:
src [heads/master●] % gn gen out/ios_64 --args='target_os="ios" target_cpu="arm64"'
ERROR at //build/config/ios/ios_sdk.gni:109:21: Script returned non-zero exit code.
_ios_sdk_result = exec_script(script_name, ios_sdk_info_args, "scope")
^----------
Current dir: /Users/lynn/code/webrtc_ios/src/out/ios_64/
Command: python /Users/lynn/code/webrtc_ios/src/build/config/mac/sdk_info.py --get_sdk_info iphoneos
Returned 1.
stderr:
Traceback (most recent call last):
File "/Users/lynn/code/webrtc_ios/src/build/config/mac/sdk_info.py", line 107, in <module>
FillXcodeVersion(settings, args.developer_dir)
File "/Users/lynn/code/webrtc_ios/src/build/config/mac/sdk_info.py", line 59, in FillXcodeVersion
settings['xcode_version'] = FormatVersion(lines[0].split()[-1])
File "/Users/lynn/code/webrtc_ios/src/build/config/mac/sdk_info.py", line 43, in FormatVersion
major, minor, patch = SplitVersion(version)
File "/Users/lynn/code/webrtc_ios/src/build/config/mac/sdk_info.py", line 30, in SplitVersion
version = version.split('.')
TypeError: a bytes-like object is required, not 'str'
See //build/config/sysroot.gni:67:3: whence it was imported.
import("//build/config/ios/ios_sdk.gni")
^--------------------------------------
See //build/config/linux/pkg_config.gni:5:1: whence it was imported.
import("//build/config/sysroot.gni")
^----------------------------------
See //BUILD.gn:15:1: whence it was imported.
import("//build/config/linux/pkg_config.gni")
^-------------------------------------------
当我将有问题的 Python 脚本编辑为 时print(sys.version)
,它显示它正在运行 Python 3,即使脚本应该在.vpython
.
如何配置gn
以使用适当的 Python 版本运行这些脚本?
解决方案
似乎exec_script
正在使用机器 Python 版本运行这些脚本。gn help exec_script
说:
默认的脚本解释器是 Python(在 POSIX 上为“python”,在 Windows 上为“python.exe”或“python.bat”)。这可以通过 script_executable 变量进行配置,参见“gn help dotfile”。
对我来说,python
指向 Python 3。所以我不得不将此行添加到 .gn 点文件的末尾:
script_executable = "vpython"
现在构建使用 中定义的虚拟 Python .vpython
,即 Python 2.7。
(vpython
可执行文件由 Chromium depot_tools 提供,就像gn
.)
推荐阅读
- javascript - 在 Moodle 中将变量值从 php 发送到 js 脚本的最佳方式
- lua - Kong-OIDC 插件安装问题
- python - Pyspark数据框将函数应用于一行并将行添加到数据框的底部
- python - 从 Windows 上的命令提示符下载 python
- sql-server - 有没有办法告诉 SQL Server 在插入每个新行之前检查表中的重复项?
- java - 如何从 Maven 依赖项中获取类文件到 target\classes 文件夹
- javascript - kinesis 视频流 webrtc 403 在预签名的 websocket wss url 上被禁止
- python - Dockerized Python 项目 - 管理依赖项的最佳方式:Dockerfile 或 requirements.txt
- excel - Google 地图未显示在 Microsoft Excel 数据输入表单中
- vagrant - Vagrantfile - 以相同主机名显示的多台虚拟机