Mac OS Catalina系统下PyQt4安装问题求助(Anaconda环境)
Hey there, I feel your pain—stuck maintaining legacy PyQt4 code but hitting walls with Anaconda and pip not providing working packages for Catalina. Let’s break down the reliable workarounds to get this up and running:
Option 1: Compile PyQt4 from Source (Using Homebrew for Qt4)
Since official repositories dropped Qt4 support, we’ll use a third-party Homebrew tap to get Qt4, then build PyQt4 in your conda environment:
- Add the Qt4 Homebrew tap (official Homebrew removed Qt4 years ago):
brew tap cartr/qt4 - Install Qt4 via Homebrew:
brew install qt@4 - Create a dedicated conda environment (PyQt4 works best with Python 3.6 or older—newer versions have compatibility issues):
conda create -n pyqt4_env python=3.6 conda activate pyqt4_env - Install a compatible SIP version (PyQt4 requires SIP < 5; version 4.19.13 is tested):
pip install sip==4.19.13 - Set environment variables to let your conda Python find Qt4’s libraries and headers:
export PATH="/usr/local/opt/qt@4/bin:$PATH" export DYLD_LIBRARY_PATH="/usr/local/opt/qt@4/lib:$DYLD_LIBRARY_PATH" export CFLAGS="-I/usr/local/opt/qt@4/include $CFLAGS" export LDFLAGS="-L/usr/local/opt/qt@4/lib $LDFLAGS" - Install PyQt4 from source (skip pre-built wheels since they don’t work on Catalina):
Note: If Catalina blocks the Qt4 libraries afterward, go to System Preferences > Security & Privacy and allow the blocked software.pip install PyQt4 --no-binary :all:
Option 2: Use a Third-Party Conda Repository
If compiling feels too tedious, try this third-party conda channel that still hosts PyQt4 packages:
conda create -n pyqt4_env python=3.6 conda activate pyqt4_env conda install -c free pyqt=4
Heads up: This channel isn’t maintained as actively, so check for version conflicts with your other packages.
A Quick Note on Long-Term Maintenance
While these fixes get you up and running, keep in mind that PyQt4 is end-of-life and no longer receives security updates. If possible, consider incrementally migrating your code to PyQt5—most APIs are similar, and the transition is manageable with gradual refactoring.
内容的提问来源于stack exchange,提问作者Javier

