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

Ubuntu18.04 Conda环境中PyQt5导入QtWebEngineWidgets失败求助

ImportError when importing QtWebEngineWidgets from PyQt5 (Ubuntu 18.04 Conda Env)

Environment Details

  • Ubuntu 18.04 operating system
  • Conda environment running Python 3.7.7
  • PyQt5 5.15.2 and PyQtWebEngine 5.15.2 installed via pip

The Problem

When running the line from PyQt5 import QtWebEngineWidgets, I hit an ImportError with this message:

/usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2: symbol krb5_ser_context_init version krb5_3_MIT not defined in file libkrb5.so.3 with link time reference

Fixes I’ve Tried (None Worked)

  • Reinstalled PyQt5, PyQtWebEngine, and related libraries
  • Followed PySide2-based solutions and ran conda install -c conda-forge PyQt5
  • Installed then removed the system package python3-pyqt5
  • Checked that LD_LIBRARY_PATH isn’t set globally, ruling out path conflicts

Additional Context

  • This issue doesn’t happen in a Windows + pip environment
  • I must use PyQt5 with Conda because of existing code dependencies
  • Key packages from my environment:
    • pip list: PyQt5 5.15.2, PyQtWebEngine 5.15.2
    • conda list: krb5 1.18.2, Python 3.7.7

Solution

This error pops up because there’s a version clash between the krb5 library included with your Ubuntu system and the one installed in your Conda environment. Here’s how to fix it:

  1. Prioritize Conda’s krb5 library
    The system’s older krb5 library is loading before Conda’s, causing the symbol mismatch. Run this command in your terminal right before launching your Python script (or add it to your shell profile to make it permanent for the environment):

    export LD_LIBRARY_PATH=$CONDA_PREFIX/lib:$LD_LIBRARY_PATH
    

    This tells your system to check the Conda environment’s lib folder first, so it uses the correct krb5 1.18.2 version that matches your setup.

  2. Pin the krb5 version in your environment
    To prevent this issue from coming back, lock the krb5 version in your environment.yml file. Add this line under the dependencies section:

    - krb5=1.18.2
    

    Then run conda env update --file environment.yml to apply the change. This ensures Conda won’t accidentally update krb5 to a conflicting version later.

  3. Recreate the environment from scratch (if needed)
    If the first two steps don’t resolve the issue, a clean environment might be the most reliable fix. Create a new Conda environment with the exact versions you need:

    conda create -n your_env_name python=3.7.7 krb5=1.18.2
    conda activate your_env_name
    pip install PyQt5==5.15.2 PyQtWebEngine==5.15.2
    

    This sets up all dependencies in a fresh state, eliminating any leftover conflicting files from previous installs.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.11 07:25:50