Ubuntu18.04 Conda环境中PyQt5导入QtWebEngineWidgets失败求助
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_PATHisn’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:
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_PATHThis tells your system to check the Conda environment’s
libfolder first, so it uses the correct krb5 1.18.2 version that matches your setup.Pin the krb5 version in your environment
To prevent this issue from coming back, lock the krb5 version in yourenvironment.ymlfile. Add this line under thedependenciessection:- krb5=1.18.2Then run
conda env update --file environment.ymlto apply the change. This ensures Conda won’t accidentally update krb5 to a conflicting version later.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.2This sets up all dependencies in a fresh state, eliminating any leftover conflicting files from previous installs.
内容的提问来源于stack exchange,提问作者grzegorzs

