You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GStreamer Python绑定libgstpython.so被列入黑名单问题求助

Ubuntu 24.04 Docker环境下GStreamer Python绑定libgstpython.so被列入黑名单的解决方法

问题描述

在Ubuntu 24.04的Docker环境中安装GStreamer的Python绑定,所有安装步骤无报错,但libgstpython.so库被列入黑名单。无论是通过源码编译还是安装gstreamer1.0-python3-plugin-loader均出现此问题。尝试过更换Python版本、指定Python路径等方法,均未解决。调试日志关键错误为:

** (gst-plugin-scanner:15): CRITICAL **: 18:14:35.880: gi.repository.Gst is no dict。

我的Dockerfile

FROM ubuntu:24.04

# Install Python
ARG PYTHON_VERSION=3.9.18
WORKDIR /opt
RUN apt update -y && apt upgrade -y && \
    apt install -y libbz2-dev libsqlite3-dev zlib1g-dev libffi-dev wget curl build-essential libssl-dev openssl vim && \
    wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz && \
    tar xzvf Python-${PYTHON_VERSION}.tgz && \
    cd Python-${PYTHON_VERSION} && \
    ./configure --enable-shared && \
    make && \
    make install && \
    ln -s /usr/local/bin/python3 /usr/bin/python && \
    ln -s /usr/local/bin/pip3 /usr/bin/pip

# Install FFmpeg, GStreamer, and reqs for custom plugins
RUN apt update && apt upgrade -y && apt install -y \
    ffmpeg \
    libgstreamer1.0-dev \
    libgstreamer-plugins-base1.0-dev \
    libgstreamer-plugins-bad1.0-dev \
    libhdf5-dev \
    gstreamer1.0-plugins-base \
    gstreamer1.0-plugins-base-apps \
    gstreamer1.0-plugins-good \
    gstreamer1.0-plugins-bad \
    gstreamer1.0-plugins-ugly \
    gstreamer1.0-libav \
    gstreamer1.0-tools \
    gstreamer1.0-x \
    gstreamer1.0-alsa \
    gstreamer1.0-gl \
    gstreamer1.0-gtk3 \
    gstreamer1.0-qt5 \
    gstreamer1.0-pulseaudio \
    graphviz \
    python3-gi \
    python3-gst-1.0 \
    libgirepository1.0-dev \
    cmake \
    python-gi-dev \
    libcairo2-dev \
    ninja-build \
    git \
    flex \
    bison

# NOTE: pygobject 3.47.0 introduced a bug
WORKDIR /opt
RUN pip install pycairo pygobject==3.46.0 meson pipenv
RUN GSTREAMER_VERSION=$(gst-launch-1.0 --version | grep version | tr -s ' ' '\n' | tail -1) \
    && export GIT_SSL_NO_VERIFY=1 \
    && git clone https://gitlab.freedesktop.org/gstreamer/gstreamer.git \
    && cd gstreamer \
    && git checkout $GSTREAMER_VERSION \
    && cd subprojects/gst-python \
    && PREFIX=$(dirname $(dirname $(which python))) \
    && meson setup --prefix=$PREFIX builddir \
    && ninja -C builddir \
    && meson install -C builddir

# Install other dependencies
ENV GST_PLUGIN_PATH=/usr/lib/aarch64-linux-gnu/gstreamer-1.0

gst-inspect-1.0 -b输出

# gst-inspect-1.0 -b
Blacklisted files:
  libgstpython.so

Total count: 1 blacklisted file

解决方法

1. 修复Python环境冲突

手动编译的Python 3.9与系统自带Python环境存在依赖冲突,GStreamer扫描插件时调用了错误的Python环境,导致GI库加载异常。

  • 若坚持使用自定义编译Python,编译时需添加参数对接系统依赖库:
    ./configure --enable-shared --with-system-expat --with-system-ffi
    
  • 更简便的方式是直接使用Ubuntu 24.04默认的Python 3.10,避免环境冲突。

2. 修正GST_PLUGIN_PATH环境变量

自定义编译的gst-python会安装到/usr/local/lib/gstreamer-1.0,当前环境变量仅指向系统路径,导致GStreamer无法找到插件。修改为:

ENV GST_PLUGIN_PATH=/usr/local/lib/gstreamer-1.0:/usr/lib/aarch64-linux-gnu/gstreamer-1.0

3. 避免重复安装gst-python

同时通过apt和源码编译安装gst-python会导致版本冲突,选择其中一种方式即可:

  • 用apt安装则删除源码编译步骤;
  • 用源码编译则先卸载apt包:
    apt remove -y python3-gst-1.0
    

4. 验证GI库可用性

在容器中运行以下命令,检查GI库是否能正常导入:

python -c "import gi; gi.require_version('Gst', '1.0'); from gi.repository import Gst; Gst.init(None)"

若报错,需重新安装python3-gi和pygobject,确保版本匹配。

修正后的Dockerfile示例

FROM ubuntu:24.04

# 使用系统默认Python,避免环境冲突
WORKDIR /opt
RUN apt update -y && apt upgrade -y && \
    apt install -y \
    ffmpeg \
    libgstreamer1.0-dev \
    libgstreamer-plugins-base1.0-dev \
    libgstreamer-plugins-bad1.0-dev \
    gstreamer1.0-plugins-base \
    gstreamer1.0-plugins-good \
    gstreamer1.0-plugins-bad \
    gstreamer1.0-plugins-ugly \
    gstreamer1.0-libav \
    gstreamer1.0-tools \
    python3-gi \
    python3-gst-1.0 \
    libgirepository1.0-dev \
    python3-pip \
    git \
    ninja-build \
    meson

# 安装指定版本的pygobject,避免bug
RUN pip3 install pycairo pygobject==3.46.0

# 设置正确的插件路径
ENV GST_PLUGIN_PATH=/usr/lib/aarch64-linux-gnu/gstreamer-1.0

内容的提问来源于stack exchange,提问作者mentoc3000

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 20:44:51