由于在服务器上编译软件需要在shell脚本中读取yml配置,搜索结果说要安装python包yq
,几经摸索,终于安装好了。步骤如下
安装python3
可自行安装最新版本或使用系统软件包
# 查看python指向哪个版本
ls -l | grep python
sudo apt-get install python3
# 查看版本
python3 -V
安装完后检查pip3是否可用,我的是不可用,继续安装
安装pip3
Before using yq, you also have to install its dependency, jq
see jq installation instructions
cd /usr/local/lib/python3.8/dist-packages
wget http://bootstrap.pypa.io/get-pip.py
python3 get-pip.py
pip3 install yq
若直接安装yq将得到如下警告:

目前不知道直接覆盖低版本会有什么影响,所以我忽略了这个提醒。
# 安装c库依赖
sudo apt-get install jq
# 可能存在低版本的 pyYaml 依赖,安装时报警,卸载不掉,可忽略warning
pip3 install yq --ignore-installed
# 测试命令,name为yml文件的一个属性,类似于jquery的链式调用
cat config.yml | yq .name
# 或
yq .name config.yml
打印出json格式的数据则表示yq安装成功
网友评论